我使用Python的请求包和以下代码:
APIKEY = "XXX"
url = 'https://services.kommunicate.io/rest/ws/message/v2/send HTTP/1.1'
myobj = {
'groupId': "xxx",
'message':'Hello',
"fromUserName":'yyy'
}
headers = {
'Api-Key':APIKEY,
}
response = requests.post(url, data = myobj,headers=headers)
并且给了我以下错误:
'{"status":"error","errorResponse":[{"errorCode":"AL-MA-01","description":"method not allowed","displayMessage":"Request method \\u0027POST\\u0027 not supported"}],"generatedAt":1591385905404}'
我做错了什么
代码中几乎没有问题
1.
HTTP/1.1
不是URL的一部分。2.在
requests
包中,为了向服务器传递JSON,有多种方法a。使用
requests.post
方法中提供的json
参数将JSON数据发送到服务器,类似以下代码:b。在标题中添加
"Content-Type": "application/json"
,然后首先将json数据转储到字符串,然后将其发送到服务器另外,请检查Difference between data and json parameters in python requests package
相关问题 更多 >
编程相关推荐