Py学习  »  Python

Python Netsuite rest api web服务基于令牌的身份验证连接

Imran • 3 年前 • 322 次点击  

我正在尝试连接到Netsuite沙盒,该沙盒使用python配置了基于web服务令牌的身份验证,但出现错误:

“详细信息”:“登录尝试无效。有关更多详细信息,请参阅NetSuite UI中的登录审核跟踪,网址为Setup>Users/Roles>User Management>View login Audit Trail。”, “o:错误代码”:“无效的_登录”

在检查netsuite登录审核跟踪搜索时,我看到它被报告为“UnknownAlgorithm”

python代码:

import oauth2 as oauth
import requests
import time

url = "https://XXXXXXXXXXX.app.netsuite.com/services/rest/record/v1/account"

token = oauth.Token(key="XXXXXXXXXXXXXXXXXXXXXXXXXXX", secret="XXXXXXXXXXXXXXXXXXXXXXXXXXX")
consumer = oauth.Consumer(key="XXXXXXXXXXXXXXXXXXXXXXXXXXX", secret="XXXXXXXXXXXXXXXXXXXXXXXXXXX")

http_method = "GET"  
realm="XXXXXXXXX"

params = {
    'oauth_version': "1.0",
    'oauth_nonce': oauth.generate_nonce(),
    'oauth_timestamp': str(int(time.time())),
    'oauth_token': token.key,
    'oauth_consumer_key': consumer.key
}

req = oauth.Request(method=http_method, url=url, parameters=params)
signature_method = oauth.SignatureMethod_HMAC_SHA1()
req.sign_request(signature_method, consumer, token)
realm="XXXXXXXXX"
header = req.to_header(realm)
headery = header['Authorization'].encode('ascii', 'ignore')
headerx = {"Authorization": headery, "Content-Type":"application/json"}
print(headerx)
conn = requests.get("https://XXXXXXXXXXX.app.netsuite.com/services/rest/record/v1/account",headers=headerx)
print(conn.text)

输出:

{“类型”:https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2“,”标题“:”未经授权“,”状态“:401,“o:errorDetails:”[{“detail:”无效登录尝试“,”o:errorCode:”无效登录尝试“}]}

连接到Netsuite需要做哪些更改?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/129187
 
322 次点击