Hi,
Since I update arcgis 104.1 to 10.5.1, I have an issue when i want to generate token :
parameters = urllib.urlencode({'username' : username,
'password' : password,
'client' : 'referer',
'referer': portalUrl,
'expiration': 60,
'f' : 'json'})
response = urllib.urlopen(portalUrl + '/sharing/rest/generateToken?', parameters).read()
try:
jsonResponse = json.loads(response)
if 'token' in jsonResponse:
self.token = jsonResponse['token']
return self.token
elif 'error' in jsonResponse:
print(jsonResponse['error']['message'])
for detail in jsonResponse['error']['details']:
print(detail)
sys.exit(2)
except ValueError, e:
print('An unspecified error occurred.')
print(e)
IOError: [Errno socket error] [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)
Do you have any idea to solve this issue ?
Thx.
Solved! Go to Solution.
Hi Magaly,
Try the following. The try/except should bypass the SSL Certificate error.
import urllib, urllib2, json, ssl
username = "portal"
password = "agol123"
tokenURL = 'https://portal.esri.com/portal/sharing/rest/generateToken/'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'https://portal.esri.com'}
req = urllib2.Request(tokenURL, urllib.urlencode(params))
try:
response = urllib2.urlopen(req)
except:
gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
response = urllib2.urlopen(req, context=gcontext)
data = json.load(response)
token = data['token']
print(token)
Hi Magaly,
Try the following. The try/except should bypass the SSL Certificate error.
import urllib, urllib2, json, ssl
username = "portal"
password = "agol123"
tokenURL = 'https://portal.esri.com/portal/sharing/rest/generateToken/'
params = {'f': 'pjson', 'username': username, 'password': password, 'referer': 'https://portal.esri.com'}
req = urllib2.Request(tokenURL, urllib.urlencode(params))
try:
response = urllib2.urlopen(req)
except:
gcontext = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
response = urllib2.urlopen(req, context=gcontext)
data = json.load(response)
token = data['token']
print(token)
I'm trying to run the example python script here:
and am getting the same error on our 10.5.1 Portal - could you show me how to bypass the SSL error using this script as an example? Thanks!
Thank you very much, it works !!