Token: OSError: Int or String expected

1605
3
05-26-2021 04:27 AM
CliveSwan
Occasional Contributor II

Greetings,

I am unable to get the Token in my current environment, due to certificates??

I am trying to get a request working to retrieve the token but keep getting an <OSError: Int or String expected> error??

The code is:

params = {'username': username, 'password': password, 'referer': bccreferer, 'f': 'pjson'}
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "*.*"}
port = 6443

#### For Python 3
#### req = urllib.request("POST"(tokenURL, urlencode(params)))
#### response = urlopen(req)
conn = http.client.HTTPSConnection(tokenURL, params)
conn.request("POST", "", params, headers)
response = conn.getresponse()
print(response.status, response.reason)

 

The error points to: 

conn.request("POST", "", params, headers)

 

I would appreciate any pointers to resolve this issue.

Regards,

Clive

Tags (4)
0 Kudos
3 Replies
MichaelVolz
Esteemed Contributor

I am trying to get similar code to work with https protocol as I was able to get it to work with http protocol, but that would not meet production security requirements.

Did you pull this code from an ESRI sample?  I ask because I have a line of code that is similar, but there is a difference so I'm wondering if that could be part of your problem.

params = urllib.urlencode({'username': username, 'password': password, 'client': 'requestip', 'f': 'json'})

0 Kudos
RandallWilliams
Esri Regular Contributor

I think that the issue is that you're sending a POST with query parameters in the URL string instead of inside the post body. 

0 Kudos
MichaelVolz
Esteemed Contributor

Can you please make a suggestion on how it should be formatted in order to work?  I am having similar issues with this type of script and currently I am sort of at a loss for what the root cause of the issue is.

I can make this http call manually in a browser 

http://"fully qualified server domain name":6080/arcgis/admin/generateToken

I can also make this https call manually in a brower

https://"web adaptor name"/server/admin/generateToken

But when I run in python code the token does not appear to get generated successfully.

0 Kudos