Created
May 23, 2016 06:12
-
-
Save toughrogrammer/b579424278a274a1dcfcdd89cac2a554 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
| try: | |
| auth = OAuth(access_token) if use_auth else None | |
| payload_data = json.dumps(payload) if payload is not None else None | |
| if payload_data is None: | |
| request = requests.Request(method, url, params=params, auth=auth).prepare() | |
| else: | |
| request = requests.Request(method, url, params=params, data=payload_data, auth=auth).prepare() | |
| request.headers['Content-Type'] = 'application/json' | |
| req_session = requests.Session() | |
| response = req_session.send(request) | |
| if do_abort: | |
| response.raise_for_status() | |
| return response | |
| except requests.ConnectionError as e: | |
| if do_abort: | |
| abort(500) | |
| else: | |
| return None | |
| except requests.HTTPError as e: | |
| if response.headers['Content-Type'] == 'application/json': | |
| response_json = response.json() | |
| if 'reason' in response_json: | |
| reason = response_json['reason'] | |
| abort(response.status_code, reason) | |
| else: | |
| abort(response.status_code) | |
| else: | |
| abort(response.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment