正在查找使用OAuth的Netsuite API的Python代码示例?

正在查找使用OAuth的Netsuite API的Python代码示例?,python,oauth,netsuite,Python,Oauth,Netsuite,Netsuite的文档尚未提供。是否有人编写了代码来帮助我生成有效的签名。NetSuite answers站点中有一些示例代码,但您必须登录才能访问它 这是我能做的答案中的代码。唯一的区别是,他们的代码试图将时间戳编码为int,结果被破坏了。我将其键入str,编码工作正常。密钥/令牌/领域来自它们的演示代码。插入你自己的,你应该很好去 import oauth2 as oauth import requests import time url = "https://rest.netsuite

Netsuite的文档尚未提供。是否有人编写了代码来帮助我生成有效的签名。

NetSuite answers站点中有一些示例代码,但您必须登录才能访问它

这是我能做的答案中的代码。唯一的区别是,他们的代码试图将时间戳编码为int,结果被破坏了。我将其键入str,编码工作正常。密钥/令牌/领域来自它们的演示代码。插入你自己的,你应该很好去

import oauth2 as oauth
import requests
import time

url = "https://rest.netsuite.com/app/site/hosting/restlet.nl?script=992&deploy=1"
token = oauth.Token(key="080eefeb395df81902e18305540a97b5b3524b251772adf769f06e6f0d9dfde5", secret="451f28d17127a3dd427898c6b75546d30b5bd8c8d7e73e23028c497221196ae2")
consumer = oauth.Consumer(key="504ee7703e1871f22180441563ad9f01f3f18d67ecda580b0fae764ed7c4fd38", secret="b36d202caf62f889fbd8c306e633a5a1105c3767ba8fc15f2c8246c5f11e500c")

http_method = "GET"  
realm="ACCT123456"

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)
header = req.to_header(realm)
headery = header['Authorization'].encode('ascii', 'ignore')
headerx = {"Authorization": headery, "Content-Type":"application/json"}
print(headerx)
conn = requests.get("https://rest.netsuite.com/app/site/hosting/restlet.nl?script=992&deploy=1",headers=headerx)
print(conn.text)

仅供参考,我最近在Python3中使用
requests\u oauthlib
实现了这一点,并且它与库的标准使用一起工作:

from requests_oauthlib import OAuth1Session
import json

url = 'https://xxx.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=xxx&deploy=xxx'

oauth = OAuth1Session(
    client_key='xxx',
    client_secret='xxx',
    resource_owner_key='xxx',
    resource_owner_secret='xxx',
    realm='xxx')

payload = dict(...)
resp = oauth.post(
    url,
    headers={'Content-Type': 'application/json'},
    data=json.dumps(payload),
)

print(resp)

谢谢这是用于NLAuth(用户/密码)。我正在寻找OAuth。这种使用OAuth的方法不再有效。Netsuite需要SHA256签名。不推荐使用SHA1。