Skip to content

Instantly share code, notes, and snippets.

@axilaris
Created October 6, 2021 09:07
Show Gist options
  • Save axilaris/6ecc58e43895dba17ce0ca1b8ce25d9a to your computer and use it in GitHub Desktop.
Save axilaris/6ecc58e43895dba17ce0ca1b8ce25d9a to your computer and use it in GitHub Desktop.
import oauth2 as oauth
import json
import requests
import time
url = "https://1234567-sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=553&deploy=1"
token = oauth.Token(key="1638cc7b433261eeed83462336e4fabfd34442cad601dfa486f98752ebc40554",
secret="273dfacad10fc828994f66e7c16d45247b7420780a15801d5bb8541095209935")
consumer = oauth.Consumer(key="911d0e2e75cb5a7105f0326d11bc4ba36985113a4add262e377aae427e367ff2",
secret="615b96eb91be2b7f32987f2570245bc5eb830130c3a713c5ea25866e213597cb")
http_method = "POST"
realm = "1234567_SB1" # NetSuite account ID
# the JSON data to be sent to the RESTlet
payload = {
"name":"value",
"foo":"bar",
"duck":"hunt",
}
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.post(url, headers=headerx, data=json.dumps(payload))
conn = requests.post(url, headers=headerx)
print("Result: " + conn.text)
print(conn.headers)
@axilaris
Copy link
Author

axilaris commented Oct 6, 2021

"message" : "Invalid login attempt."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment