I am trying to fetch the records from Netsuite using Python. I am able to run the same script on Postman but when I try to run the same script on python it throws an error - "Invalid Login Attempt.
The code is as follows -
import os
import requests
import hashlib
import hmac
import time
import random
{account}{consumer_key}{token_id}{nonce}{timestamp}{signature}false1000false
"""
# Make the request
url = "https://{account}.suitetalk.api.netsuite.com/services/NetSuitePort_2017_1"
response = requests.post(url, headers=headers, data=body)
# Handle the response
if response.status_code == 200:
# Request was successful
print(response.text)
else:
# Request failed
print(f"Error: {response.status_code} - {response.text}")
Error- 500 is being thrown and while using GET request we are able to establish the connection using same credentials.
I am trying to fetch the records from Netsuite using Python. I am able to run the same script on Postman but when I try to run the same script on python it throws an error - "Invalid Login Attempt.
The code is as follows - import os import requests import hashlib import hmac import time import random
Environment variables
account = "account" consumer_key = "consumer_key" consumer_secret = "consumer_secret" token_id = "token_id" token_secret = "token_secret"
Calculate signature
nonce = str(random.getrandbits(64)) timestamp = str(int(time.time())) base_string = f"{account}&{consumer_key}&{token_id}&{nonce}&{timestamp}" key = f"{consumer_secret}&{token_secret}" signature = hmac.new(key.encode(), base_string.encode(), hashlib.sha256).digest().hex()
headers = { "Content-Type": "text/xml", "SOAPAction": "get", "recordType": "job" }
body = f"""