Ejemplo n.º 1
0
 def get_json(self, uri, params=None, headers=None):
     try:
         resp = requests.get(uri, params=params, headers=headers,
                             timeout=self.timeout, verify=self.verify_ssl_certs)
     except requests.exceptions.SSLError as e:
         raise api_call_error.APIInvalidSSLCertificateError(str(e))
     except requests.exceptions.ConnectionError as e:
         raise api_call_error.APIInvalidSSLCertificateError(str(e))
     except requests.exceptions.Timeout:
         raise api_call_error.APICallTimeoutError('API call timeouted')
     HttpClient.check_status_code(resp.status_code, resp.text)
     try:
         return resp.status_code, resp.json()
     except:
         raise parse_response_error.ParseResponseError('Impossible to parse'
                                                       'API response data')
Ejemplo n.º 2
0
 def post(self, uri, params=None, data=None, headers=None):
     try:
         resp = requests.post(uri, params=params, json=data, headers=headers,
                              timeout=self.timeout, verify=self.verify_ssl_certs)
     except requests.exceptions.SSLError as e:
         raise api_call_error.APIInvalidSSLCertificateError(str(e))
     except requests.exceptions.ConnectionError as e:
         raise api_call_error.APIInvalidSSLCertificateError(str(e))
     except requests.exceptions.Timeout:
         raise api_call_error.APICallTimeoutError('API call timeouted')
     HttpClient.check_status_code(resp.status_code, resp.text)
     # this is a defense against OWM API responses containing an empty body!
     try:
         json_data = resp.json()
     except:
         json_data = {}
     return resp.status_code, json_data
Ejemplo n.º 3
0
 def get_geotiff(self, uri, params=None, headers=None):
     if headers is None:
         headers = {'Accept': ImageTypeEnum.GEOTIFF.mime_type}
     else:
         headers.update({'Accept': ImageTypeEnum.GEOTIFF.mime_type})
     try:
         resp = requests.get(uri, stream=True, params=params, headers=headers,
                             timeout=self.timeout, verify=self.verify_ssl_certs)
     except requests.exceptions.SSLError as e:
         raise api_call_error.APIInvalidSSLCertificateError(str(e))
     except requests.exceptions.ConnectionError as e:
         raise api_call_error.APIInvalidSSLCertificateError(str(e))
     except requests.exceptions.Timeout:
         raise api_call_error.APICallTimeoutError('API call timeouted')
     HttpClient.check_status_code(resp.status_code, resp.text)
     try:
         return resp.status_code, resp.content
     except:
         raise parse_response_error.ParseResponseError('Impossible to parse'
                                                       'API response data')