POST https://maxcvservices.dnb.com/rest/Authentication
x-dnb-user: MyUsername
x-dnb-pwd: MyPassword
是D&B API的文档,因此我尝试使用python请求模块使用以下代码行发送POST请求:
r = requests.post('https://maxcvservices.dnb.com/rest/Authentication',params={'x-dnb-user':userid,'x-dnb-pwd':pass})
我得到的回应是 Response [500]
响应的内容是: error processing request\r\n
我的问题是我在传递帖子请求和参数时是否做错了,还是我的用户名和密码无效?
我觉得问题出在我传递POST请求的方式上,因为API会针对错误的用户ID传递一个单独的错误401进行响应。
{'connection': 'Keep-Alive',
'content-encoding': 'gzip',
'content-length': '46',
'content-type': 'text/plain',
'date': 'Sat, 26 Oct 2013 17:43:22 GMT',
'server': '',
'vary': 'Accept-Encoding',
'x-correlationid': 'Id-d4c07ad3526bff3a03fb742e 0'}
我使用时的响应标头:
r = requests.post('https://maxcvservices.dnb.com/rest/Authentication', headers={'x-dnb-user': 'userid', 'x-dnb-pwd': 'password'})
随机的用户名和密码。
但是根据API我应该会收到<Response [401]>
。我收到了<Response [500]>
。
这些是HTTP标头;引用API文档:
通过使用身份验证令牌来管理对D&B Direct服务的安全访问,可以通过向身份验证服务URL发送HTTP POST请求并在HTTP标头中传递有效的用户名和密码来获得该令牌。
这样添加它们:
r = requests.post(
'https://maxcvservices.dnb.com/rest/Authentication',
headers={'x-dnb-user': userid, 'x-dnb-pwd': password})
尽管我收到401响应(因为我没有任何有效的凭据),但这对我有用:
>>> import requests
>>> requests.__version__
'2.0.0'
>>> r = requests.post('https://maxcvservices.dnb.com/rest/Authentication',
... headers={'x-dnb-user': 'userid', 'x-dnb-pwd': 'password'})
>>> r
<Response [401]>
>>> r.headers['authorization']
'INVALID CREDENTIALS'
完全按文件记录。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句