New to Lambda and trying to figure out something basic. Have a function that is making calls to an external REST server. I can run this Python code on my local test system without issue:
payload = {'userName': user_name, 'password': password}
r = requests.post(api_base + "/session",
data=json.dumps(payload),
headers={'accept': 'application/json',
'Content-Type': 'application/json'}
)
But when i run it in lambda I get odd errors from the my log message that prints out the exception in CloudWatch (obscured my URL):
No connection adapters were found for '""/session'
If I hard-code the URL then it works fine. Is there some problem with forming the URL in Python that perhaps has different behaviors between the Python versions (I'm using 2.7.14)? The quoting in the exception string that I logged makes me believe that string concatenation is working differently between systems.
I'm was also having a horrible time loading zip files and editing in the browser today but it seems like it perhaps is related to some recent changes effecting Chrome since when i switch to Explorer things work fine.
Here is more of the relevant code:
try:
# Get session key
payload = {'userName': user_name, 'password': password}
if DEBUG:
print("api_base = ", api_base, ", full url = ", api_base + "/session")
r = requests.post(api_base + "/session",
data=json.dumps(payload),
headers={'accept': 'application/json',
'Content-Type': 'application/json'}
)
# Check return status
if r.status_code != 200:
if DEBUG:
print("HTTP Request error: ", r.status_code,
", data = ", payload,
", api_base = ", api_base)
return ""
session_data = r.json()
return session_data['token']
except requests.exceptions.RequestException as e:
print(e)
return ""
Executing this code on my local machine works just fine. When I run it in lambda I get the following output:
api_base = "https://[redacted].com/rest" , full url = "https://[redacted].com/rest"/session No connection adapters were found for '"https://[redacted].com/rest"/session'
I redacted with '[]' the basename of the URL for security reasons. As you can see, lambda seems to print the string concatenation with strange quoting.
-Wayland