1. 程式人生 > >{"errmsg":"不合法的引數","errcode":40035} 叮叮報警寫入失敗

{"errmsg":"不合法的引數","errcode":40035} 叮叮報警寫入失敗

first try:

import requests



def alert(con):
    url = "https://oapi.dingtalk.com/robot/send"
    querystring = {"access_token":"d8****f3a2a"}

    payload = "{\"msgtype\": \"text\",\"text\": {\"content\": %s,\"at\": {\"isAtAll\": true}}"%con
    headers = {
        'content-type': "application/json",
        'cache-control': "no-cache",
        'postman-token': "44***5"
        }


    response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

    print(response)
    print(response.text)

 
alert("begin")

 

 

second:

import requests

import json

def alert(con):
    url = "https://oapi.dingtalk.com/robot/send"
    querystring = {"access_token":"d**a"}

    data = {
        "msgtype" : "text",
        "text" : {
            "content" : con,
            "at" : {
                'isAtAll' : True
            }
        }
    }
    json_str = json.dumps(data)
    headers = {
        'content-type': "application/json",
        'cache-control': "no-cache",
        'postman-token': "4***05"

        }

    response = requests.request("POST", url, data=json_str, headers=headers, params=querystring)

    print(response)
    print(response.text)
    

這樣就好了, payload = "{\"msgtype\": \"text\",\"text\": {\"content\": %s
,\"at\": {\"isAtAll\": true}}"%con

 payload是json 後的資料,直接用python的 json.dumps()就OK了