我一直在尝试让 NetSuite Restlet 与 Python 3.3 一起使用urllib
,但我似乎无法获得授权并不断返回urllib.error.HTTPError: HTTP Error 401: Authorization Required
错误。
我在哪里进行身份验证?
我的测试代码如下:
import urllib.request
url = 'https://rest.netsuite.com/app/site/hosting/restlet.nl?script=123&deploy=15&recordtype=salesorder&id=123456789'
authorization = 'NLAuth nlauth_account=111111,nlauth_email=email@email.com,nlauth_signature=password,nlauth_role=3'
req = urllib.request.Request(url)
req.add_header('Authorization', authorization)
req.add_header('Content-Type','application/json')
req.add_header('Accept','*/*')
response = urllib.request.urlopen(req)
the_page = response.read()
作为参考,NetSuite 的 REST 帮助用于构建授权字符串以及位于此处的 urllib 上的 Python 文档
- 编辑 -
通过 REST 控制台传递(和工作)的标头如下所示:
Accept: application/json
Authorization: NLAuth nlauth_account=111111,nlauth_email=user@email.com,nlauth_signature=password,nlauth_role=3
Connection: keep-alive
Content-Type: application/xml
Origin: chrome-extension: //rest-console-id
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
Python 的标头输出显示为:
{'Content-type': 'application/xml', 'Accept': 'application/json', 'Authorization': 'NLAuth nlauth_account=111111,nlauth_email=email@email.com,nlauth_signature=password,nlauth_role=3'}
仍然不确定为什么它不起作用....