Skip to content

Instantly share code, notes, and snippets.

@bubbobne
Created July 21, 2017 12:59
Show Gist options
  • Save bubbobne/83786fae4ab117f96db8a8a12e0a205d to your computer and use it in GitHub Desktop.
Save bubbobne/83786fae4ab117f96db8a8a12e0a205d to your computer and use it in GitHub Desktop.
def get_request_to_json(url, user_name, user_password):
auth_string = '%s:%s' % (user_name, user_password)
base64string = base64.b64encode(auth_string.encode('ascii'))
headers = {'Authorization': "Basic %s" % bytes.decode(base64string)}
try:
req = urllib.request.Request(url, None, headers)
response = urllib.request.urlopen(req)
return json.loads(bytes.decode(response.read()))
except IOError as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment