I am trying to write a python script via they AWS Lambda interface to generate a token and then use that token to get various attributes of the ArcGIS portal.
The question I have is how to set up Lambda to access the various libraries correctly?
The simple script I have is getting the following so I suspect I just don't have all the libraries installed but I don't know where that needs to happen in an AWS Lambda environment.
[ERROR] NameError: name 'request' is not defined
My script is a follows:
from urllib.parse import urlencode
from urllib.request import Request, urlopen
import json
#define variables
portalUrl = "https://admin.portal.arcgis"
username = 'yyyyyyy'
password = "xxxxxxx"
# Get a security token to append to all requests
def generateToken(username, password, portalUrl):
# Retrieves a token to be used with API requests.
headers = {'content-type': 'application/x-www-form-urlencoded'}
parameters = {'username': username,
'password': password,
'client': 'referer',
'referer': portalUrl,
'expiration': 60,
'f': 'json'}
url = portalUrl + '/sharing/rest/generateToken?'
response = request.post(url, data=parameters, headers=headers)
Solved! Go to Solution.
Think you've missed the capital letter.
response = request.post(url, data=parameters, headers=headers)
response = Request.post(url, data=parameters, headers=headers)
Think you've missed the capital letter.
response = request.post(url, data=parameters, headers=headers)
response = Request.post(url, data=parameters, headers=headers)
Thanks @DavidPike , sometimes you can't see the forest for the trees 🙂