Greetings,
I am using the ESRI sample code to generate a token (Scripting with the ArcGIS REST API—Portal for ArcGIS | Documentation for ArcGIS Enterprise ), getting an expected type error??
Error is Expected type 'Optional[bytes]', got 'str' instead??
I updated the code for Python 3.
### Python 3.8
def generateToken(username, password, portalUrl😞
'''Retrieves a token to be used with API requests.'''
portalUrl = myurl
username = myuser
password = mypassword
parameters = urllib.parse.urlencode({'username' : username,
'password' : password,
'client' : 'referer',
'referer' : portalUrl,
'expiration' : 60,
'f' : 'json'})
print("Read parameters")
response = urllib.request.urlopen(portalUrl + '/sharing/rest/generateToken?', parameters).read()
print("response")
try:
jsonResponse = json.loads(response)
if 'token' in jsonResponse:
return jsonResponse['token']
elif 'error' in jsonResponse:
print(jsonResponse['error']['message'])
for detail in jsonResponse['error']['details']:
print(detail)
except ValueError:
print('An unspecified error occurred.')
## End
All I get is the error message:
Expected type 'Optional[bytes]', got 'str' instead
Appreciate any assistance and pointers.
Regards,
Clive