RSGISLib HTTP Tools

Access HTTP APIs

rsgislib.tools.httptools.check_http_response(response: requests.models.Response, url: str) bool

Check the HTTP response and raise an exception with appropriate error message if request was not successful.

Parameters
  • response

  • url

Returns

rsgislib.tools.httptools.send_http_json_request(url: str, data: Optional[Dict] = None, api_key: Optional[str] = None, convert_to_json: bool = True, header_data: Optional[Dict] = None) Dict

A function which sends a http request with a json data packet. If an error occurs an exception will be raised.

Parameters
  • url – The URL for the request to be sent.

  • data – dictionary of data which can be converted to str using json.dumps.

  • api_key – if provided then the api-key will be provided via the http header.

  • convert_to_json

  • header_data – a dict of header information.

Returns

A dict of data returned from the server.

Download Data

rsgislib.tools.httptools.download_file_http(input_url: str, out_file_path: str, username: Optional[str] = None, password: Optional[str] = None, no_except: bool = True)
Parameters
  • input_url

  • out_file_path

  • username

  • password

Returns

rsgislib.tools.httptools.wget_download_file(input_url: str, out_file_path: str, username: Optional[str] = None, password: Optional[str] = None, try_number: int = 10, time_out: int = 60, input_url_md5: Optional[str] = None) -> (<class 'bool'>, <class 'str'>)

A function which downloads a file from a url using the wget command line tool. If a username or password are provided then both must be provided.

Parameters
  • input_url_md5

  • input_url – string with the URL to be downloaded.

  • out_file_path – output file name and path.

  • username – username for the download, if required. Default is None meaning it will be ignored.

  • password – password for the download, if required. Default is None meaning it will be ignored.

  • try_number – number of attempts at the download. Default is 10.

  • time_out – number of seconds to time out Default is 60.

Returns

boolean specifying whether the file had been successfully downloaded and a string with user feedback (e.g., error message)