Python连接NetSuite API时出现401未授权错误的排查求助
Python连接NetSuite API时出现401未授权错误的排查求助
有没有朋友有对接NetSuite API的经验呀?我按照官方文档一步步操作了:给管理员账号创建了带API访问权限的新角色,开启了REST API功能,也生成了令牌和密钥,但用Python代码连接的时候还是一直报401未授权错误,我用的IDE是PyCharm。
以下是我的代码:
import requests from requests_oauthlib import OAuth1 # Replace these with your actual NetSuite credentials account_id = 'my_account_id' consumer_key = 'my_consumer_key' consumer_secret = 'my_consumer_secret' token = 'my_token ' token_secret = 'my_token_secret' url = f'https://{account_id}.suitetalk.api.netsuite.com/services/rest/record/v1/customer' auth = OAuth1(consumer_key, consumer_secret, token, token_secret, signature_method='HMAC-SHA256') headers = { 'Content-Type': 'application/json' } response = requests.get(url, auth=auth, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code} - {response.json()}")
运行后得到的错误如下:
C:\Users\username\AppData\Local\Programs\Python\Python313\python.exe C:\Users\username\PycharmProjects\NetSuiteAPI\netsuite_integration.py Error: 401 - {'type': 'https://www.rfc-editor.org/rfc/rfc9110.html#section-15.5.2', 'title': 'Unauthorized', 'status': 401, 'o:errorDetails': [{'detail': 'Invalid login attempt.', 'o:errorCode': 'INVALID_LOGIN_ATTEMPT'}]}
备注:内容来源于stack exchange,提问作者b1995
相关产品推荐
相关产品推荐

