我使用的是礼貌邮件的odatarestfulapi(Doc:PoliteMail API Entity Directory)
我正在尝试用requests.post()
在礼貌邮件中创建联系人。在
下面是我的步骤
import requests
import json
# point to credentials
import os
import yaml
myKeys = yaml.load(open(os.path.join(os.path.expanduser('~'), 'Documents\keyfile2.json')))
r = requests.get(url+'(56)', auth=auth)
print(r.status_code) # '200'
我可以在这个实体中获取任何内容,但不能发布。在
下面是结构given in the documentation
payload = {
"ID":"0",
"Name":"Test List",
"Description":"Does this work",
"IsNewsletter":"0",
"Shared":False,
"CreationDate":"2014-11-19T23:00:00.000Z",
"ActiveState":"1",
"isAnonymous":False,
"BusinessID":"0",
"RegionID":"0"
}
我的请求:
r = requests.post(url, data=json.dumps(payload),auth=auth)
它是输出
415: The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource."
但当我为内容类型添加标题时:
r = requests.post(url, data=json.dumps(payload),auth=auth,
headers = {"Content-Type": "application/json"})
有人告诉我:
400 "The request is invalid." An error has occurred.\r\n","type":"","stacktrace":""
我试过以下几种方法,但没有效果:
json=
而不是{非常感谢任何帮助!在
错误来自解析后的文本,下面是我使用BeautifulSoup
时的完整响应读数
{
"odata.error":{
"code":"","message":{
"lang":"en-US","value":"The request is invalid."
},"innererror":{
"message":"contact : An error has occurred.\r\n","type":"","stacktrace":""
}
}
}
通过将有效载荷中False的大写字母改为False和isAnonymous到isAnonymous来创建一个列表。在
你在帖子的开头还提到了创建联系人。我成功地与以下人员建立了联系。在
^{pr2}$我在PoliteMail工作,曾在内部请求更新文档,以修复的大写字母。在
更新:文档已更新为正确的大写字母。http://kb.politemail.com/?p=1349
根据错误日志,服务器端可能不处理换行符
\r\n
。在你能试着去掉你的有效载荷的断线吗?在
相关问题 更多 >
编程相关推荐