Created
July 21, 2017 12:59
-
-
Save bubbobne/83786fae4ab117f96db8a8a12e0a205d to your computer and use it in GitHub Desktop.
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
| 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