这个错误是如此常见,以至于我发现了这个错误的几个点击。但是,找不到我的问题的解决方案。
我正在尝试使用Python中的请求模块来使用REST API(不是公开的API)。但是,API使用的规范表明我使用URI Content-type = 'application/xml'
和正文"<authCommand><userID> </userID><password> </password></authCommand>"
调用POST方法。
我在Python中使用请求尝试了这个:
r1 = requests.post('https://abc.360.net/rest/auth/1/login.xml',data= None, auth=('sdm@company.com','*********'), headers = {'content-type':'application/xml'})
当我运行它时,我收到错误的请求错误。
这是正确的做法吗?为什么我收到此错误?
答案 0 :(得分:0)
auth
参数是设置Authorization
标头(默认情况下是基本的http身份验证)。 API需要正文中的凭据:
r = request.post(url, data=xml, headers={'Content-Type': 'application/xml'})
其中xml=b"<authCommand><userID>sdm@company.com</authCommand>..."
。