def get_geotiff(self, path, params=None, headers=None): builder = HttpRequestBuilder(self.root_uri, self.api_key, self.config, has_subdomains=self.admits_subdomains)\ .with_path(path)\ .with_api_key()\ .with_language()\ .with_query_params(params if params is not None else dict())\ .with_headers(headers if headers is not None else dict())\ .with_header('Accept', ImageTypeEnum.GEOTIFF.mime_type) url, params, headers, proxies = builder.build() try: resp = requests.get(url, stream=True, params=params, headers=headers, proxies=proxies, timeout=self.config['connection']['timeout_secs'], verify=self.config['connection']['verify_ssl_certs']) except requests.exceptions.SSLError as e: raise exceptions.InvalidSSLCertificateError(str(e)) except requests.exceptions.ConnectionError as e: raise exceptions.InvalidSSLCertificateError(str(e)) except requests.exceptions.Timeout: raise exceptions.TimeoutError('API call timeouted') HttpClient.check_status_code(resp.status_code, resp.text) try: return resp.status_code, resp.content except: raise exceptions.ParseAPIResponseError('Impossible to parse' 'API response data')
def delete(self, path, params=None, data=None, headers=None): builder = HttpRequestBuilder(self.root_uri, self.api_key, self.config, has_subdomains=self.admits_subdomains)\ .with_path(path)\ .with_api_key()\ .with_language()\ .with_query_params(params if params is not None else dict())\ .with_headers(headers if headers is not None else dict()) url, params, headers, proxies = builder.build() try: resp = requests.delete(url, params=params, json=data, headers=headers, proxies=proxies, timeout=self.config['connection']['timeout_secs'], verify=self.config['connection']['verify_ssl_certs']) except requests.exceptions.SSLError as e: raise exceptions.InvalidSSLCertificateError(str(e)) except requests.exceptions.ConnectionError as e: raise exceptions.InvalidSSLCertificateError(str(e)) except requests.exceptions.Timeout: raise exceptions.TimeoutError('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 = None return resp.status_code, json_data
def get_geotiff(self, path, params=None, headers=None): # check URL fromt the metaimage: if it looks like a complete URL, use that one (I know, it's a hack...) try: partial_path = path.split(self.root_uri)[1].lstrip('/') except: partial_path = '' # fallback so that a 404 is issued builder = HttpRequestBuilder(self.root_uri, self.api_key, self.config, has_subdomains=self.admits_subdomains)\ .with_path(partial_path)\ .with_api_key()\ .with_language()\ .with_query_params(params if params is not None else dict())\ .with_headers(headers if headers is not None else dict())\ .with_header('Accept', ImageTypeEnum.GEOTIFF.mime_type) url, params, headers, proxies = builder.build() try: resp = self.http.get( url, stream=True, params=params, headers=headers, proxies=proxies, timeout=self.config['connection']['timeout_secs'], verify=self.config['connection']['verify_ssl_certs']) except requests.exceptions.SSLError as e: raise exceptions.InvalidSSLCertificateError(str(e)) except requests.exceptions.ConnectionError as e: raise exceptions.InvalidSSLCertificateError(str(e)) except requests.exceptions.Timeout: raise exceptions.TimeoutError('API call timeouted') HttpClient.check_status_code(resp.status_code, resp.text) try: return resp.status_code, resp.content except: raise exceptions.ParseAPIResponseError('Impossible to parse' 'API response data')