Unable to pass authentication information to NetSuite's REST interface using Python -


i've been trying netsuite restlet work python 3.3 using urllib, can't seem authorization take , continually return urllib.error.httperror: http error 401: authorization required error.

where going wrong authentication?

my test code 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's rest used build authorization string python docs on urllib located here

--edit--

the header passed (and works) via rest console appears 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, gecko) chrome/29.0.1547.66 safari/537.36 

headers output python appear as:

{'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's not working....

issue netsuite related (an issue roles): code below yeilds proper response:

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 e:     print("exception occurred--------------------")     print("i/o error: {0}".format(e))     print(e.headers)     print(e.headers['www-authenticate']) 

in case, original role did not have access record. confusion was expecting error of

error code: invalid_role error message:your role not give permission view page. 

to returned, not authentication required made me suspect header missing data.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -