Created
June 7, 2020 15:17
-
-
Save readytheory/8c429cfa510788f5a6976fd53d072d51 to your computer and use it in GitHub Desktop.
Call here.com from AWS lambda -- Part 1 urllib instead of requests --
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AWS doesn't allow use of request library we'd normally use, so sub out urllib | |
# Here, we alredy have a bearer token. That gets replaced daily, want to schedule it into parameter store | |
# We'll also write the data to s3 instead of returning it | |
import urllib.request as UR | |
import json | |
url = "https://traffic.ls.hereapi.com/traffic/6.2/flow.xml?bbox=38.93036,-77.17164;38.93154,-77.16965" | |
auth_info = {"access_token":"btJhbGciOiJSXlKaGJHY2lPaUprYVMamAMiAnk5TElUOXpRHAyUjRQRjZMdjGLUQREX1dnTk4wbG. . . .1GUvAlJAXe_qbJoJydw","token_type":"bearer","expires_in":86399} | |
# to make the bearer token see https://gist.github.com/readytheory/002944329327675bb2a32fbb7cae9bd7 | |
headers = {'Authorization': 'Bearer ' + auth_info["access_token"]} | |
req = UR.Request(url=url, data=None, headers=headers) | |
flow_result = UR.urlopen(req) | |
if flow_result.status != 200: | |
raise RuntimeError("Status code for headers != 200") | |
print(flow_result.status) | |
return json.dumps(flow_result.read().decode(encoding='UTF-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment