Failed to pass authentication information to NetSuite REST interface using Python

I am trying to get NetSuite Restlet to work with Python 3.3 using urllib, but I can not get authorization to take and constantly return an error urllib.error.HTTPError: HTTP Error 401: Authorization Required.

Where am I mistaken for authentication?

My test code is as follows:

import urllib.request

url = 'https://rest.netsuite.com/app/site/hosting/restlet.nl?script=123&deploy=15&recordtype=salesorder&id=123456789'

authorization = 'NLAuth nlauth_account=111111,nlauth_email=email@email.com,nlauth_signature=password,nlauth_role=3' 

req = urllib.request.Request(url)
req.add_header('Authorization', authorization)
req.add_header('Content-Type','application/json')
req.add_header('Accept','*/*')
response = urllib.request.urlopen(req)
the_page = response.read()

For reference, NetSuite REST help was used to create an authorization string, as well as Python docs on urllib located here

- EDIT -

The header that is passed (and works) through the REST Console is as follows:

Accept: application/json
Authorization: NLAuth nlauth_account=111111,nlauth_email=user@email.com,nlauth_signature=password,nlauth_role=3
Connection: keep-alive
Content-Type: application/xml
Origin: chrome-extension: //rest-console-id
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36

Python header output looks like:

{'Content-type': 'application/xml', 'Accept': 'application/json', 'Authorization': 'NLAuth nlauth_account=111111,nlauth_email=email@email.com,nlauth_signature=password,nlauth_role=3'}

still not sure why it is not working ....

+2
source share
1

NetSuite ( ): Yeilds :

import urllib.request
try:   
    url = 'https://rest.netsuite.com/app/site/hosting/restlet.nl?script=787&deploy=1&recordtype=salesorder&id=8111437'
    authorization = 'NLAuth nlauth_account=111111,nlauth_email=email@email.com,nlauth_signature=password,nlauth_role=correctRole' 
    req = urllib.request.Request(url)
    req.add_header('Authorization', authorization)
    req.add_header('Content-Type','application/xml')
    req.add_header('Accept','application/json')  
    response = urllib.request.urlopen(req)
    print(response.read())
except IOError as e:
    print("EXCEPTION OCCURRED--------------------")
    print("I/O error: {0}".format(e))
    print(e.headers)
    print(e.headers['www-authenticate'])

. ,

error code: INVALID_ROLE
error message:Your role does not give you permission to view this page.

, , .

+5

Source: https://habr.com/ru/post/1611967/


All Articles