无效的登录尝试 - 尝试点击 API

Invalid Login Attempt-While attempting to hit an API

您好,我正在尝试从 NetSuite 获取数据,但由于 INVALID LOGIN ATTEMPT 而无法这样做。我尝试了很多东西,但在我的 POSTMAN 中发现了有趣的事情,一切都运行良好。以下是我参考的几十份文件中的一些文件。

文档 1:

文档 2:https://netsuite.custhelp.com/app/answers/detail/a_id/44241/kw/SuiteTalk%20Authentication

文档 3:https://www.endyourif.com/netsuite-api-setting-up-access-token-authentication/

文档 4:https://github.com/NetSweet/netsuite/blob/master/lib/netsuite/passports/token.rb

文档 5:Implementation HMAC-SHA1 in python

这是我的代码。

nsAccountID = "1059967"
consumerKey = "434545646123fdgty7565g2bd1a71f0a2ae2badbeda67771a"
consumerSecret = "cdnc87rrth34ut4346wvnhrfg84fhf8923945u48r42fhcedw78df4"
token = "43t43f7hefc7h34fh34789fwf234rf90e89cf4h98f234"
tokenSecret = "78hf487rfy478fhc478fh34f34f3434t4yhbwae21443665u"
Nonce = self._generateNonce(length=11)
currentTime = self._generateTimestamp()
signature_method = 'HMAC-SHA256'
version = '1.0'
method = 'GET'
base_url = "https://1056867.suitetalk.api.netsuite.com/services/rest/record/v1/customer"
encoded_url = urllib.parse.quote(base_url)
collected_string = '&'.join(['oauth_consumer_key='+consumerKey, 'oauth_nonce='+Nonce,
                                     'oauth_signature_method='+signature_method, 'oauth_timestamp='+currentTime,
                                     'oauth_token='+token, 'oauth_version='+version])
encoded_string = urllib.parse.quote(collected_string)
base = '&'.join([method, encoded_url, encoded_string])
key = '&'.join([consumerSecret, tokenSecret])
digest = hmac.new(key=str.encode(key), msg=str.encode(base), digestmod=hashlib.sha256).digest()
signature = base64.b64encode(digest).decode()
url = "https://1059967.suitetalk.api.netsuite.com/services/rest/record/v1/customer"

payload = ""
headers = {
          'Content-Type': "application/json",
          'Authorization': "OAuth realm=\"1059967\","
  "oauth_consumer_key=\"434545646123fdgty7565g2bd1a71f0a2ae2badbeda67771a\","
  "oauth_token=\"43t43f7hefc7h34fh34789fwf234rf90e89cf4h98f234\","
  "oauth_signature_method=\"HMAC-SHA256\","
  "oauth_timestamp=\"" + currentTime + "\","
  "oauth_nonce=\""+Nonce+"\","
  "oauth_version=\"1.0\","
  "oauth_signature=\"" + signature + "\"",
  'cache-control': "no-cache",
            }

response = requests.request("GET", url, data=payload, headers=headers)

我也试过 sdk 即 netsuitesdk 但它给我一个错误

unable to open database file

注意:上面给出的凭据是虚拟的

在这里你可以看到我的代码。

def _generateTimestamp(self):
    return str(int(time.time()))

def _generateNonce(self, length=11):
    """Generate pseudorandom number
    """
    return ''.join([str(random.randint(0, 9)) for i in range(length)])

def _generateSignature(self, method, url, consumerKey, Nonce, currentTime, token, consumerSecret,
                       tokenSecret, offset):
    signature_method = 'HMAC-SHA256'
    version = '1.0'
    base_url = url
    encoded_url = urllib.parse.quote_plus(base_url)
    collected_string = None
    if type(offset) == int:
        collected_string = '&'.join(['oauth_consumer_key=' + consumerKey, 'oauth_nonce=' + Nonce,
                                     'oauth_signature_method=' + signature_method, 'oauth_timestamp=' + currentTime,
                                     'oauth_token=' + token, 'oauth_version=' + version, 'offset=' + str(offset)])
    else:
        collected_string = '&'.join(['oauth_consumer_key=' + consumerKey, 'oauth_nonce=' + Nonce,
                                     'oauth_signature_method=' + signature_method, 'oauth_timestamp=' + currentTime,
                                     'oauth_token=' + token, 'oauth_version=' + version])
    encoded_string = urllib.parse.quote_plus(collected_string)
    base = '&'.join([method, encoded_url, encoded_string])
    key = '&'.join([consumerSecret, tokenSecret])
    digest = hmac.new(key=str.encode(key), msg=str.encode(base), digestmod=hashlib.sha256).digest()
    signature = base64.b64encode(digest).decode()
    return urllib.parse.quote_plus(signature)

def _create_oauth(self, base_url):
    nsAccountID = 'YOUR_NETSUITE_ACCOUNT_ID'
    consumerKey = 'YOUR_NETSUITE_CONSUMER_KEY'
    consumerSecret = 'YOUR_NETSUITE_CONSUMER_SECRET'
    token = 'YOUR_NETSUITE_TOKEN'
    tokenSecret = 'YOUR_NETSUITE_TOKEN_SECRET'

    Nonce = self._generateNonce(length=11)
    currentTime = self._generateTimestamp()

    signature = self._generateSingleSignature('GET', base_url, consumerKey, Nonce, currentTime, token,
                                                  consumerSecret, tokenSecret)

    oauth = "OAuth realm=\"" + nsAccountID + "\"," \
                                                 "oauth_consumer_key=\"" + consumerKey + "\"," \
                                                                                         "oauth_token=\"" + token + "\"," \
                                                                                                                    "oauth_signature_method=\"HMAC-SHA256\"," \
                                                                                                                    "oauth_timestamp=\"" + currentTime + "\"," \
                                                                                                                                                         "oauth_nonce=\"" + Nonce + "\"," \
                                                                                                                                                                                    "oauth_version=\"1.0\"," \
                                                                                                                                                                                    "oauth_signature=\"" + signature + "\""
    headers = {
        'Content-Type': "application/json",
        'Authorization': oauth,
        'cache-control': "no-cache",
    }
    return headers

"""Here is my API call"""

base_url = "https://REALM.suitetalk.api.netsuite.com/services/rest/record/v1/salesorder/"
payload = ""
data = {}
response = requests.request("GET", base_url, data=payload, headers=self._create_oauth(base_url))