def _handle_response(response): if not response.ok: raise FinnhubAPIException(response) try: content_type = response.headers.get('Content-Type', '') if 'application/json' in content_type: return response.json() if 'text/csv' in content_type: return response.text if 'text/plain' in content_type: return response.text raise FinnhubRequestException("Invalid Response: {}".format(response.text)) except ValueError: raise FinnhubRequestException("Invalid Response: {}".format(response.text))
def _handle_response(self, response): if not str(response.status_code).startswith('2'): raise FinnhubAPIException(response) try: return response.json() except ValueError: raise FinnhubRequestException("Invalid Response: {}".format( response.text))