You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 18:28:01