obspy.clients.base.HTTPClient
- class HTTPClient(debug=False, timeout=120, user_agent='ObsPy/1.4.1.post0+358.gf5c9534772 (Linux-6.5.0-1025-azure-x86_64-with-glibc2.35, Python 3.9.19)')[source]
Bases:
RemoteBaseClient
Mix-in class to add HTTP capabilities.
- Parameters:
debug (bool) – Passed on to the
BaseClient
constructor.timeout (float) – Passed on to the
RemoteBaseClient
constructor.
Example
- from obspy.clients.base import (WaveformClient, HTTPClient,
DEFAULT_USER_AGENT)
- class NewClient(WaveformClient, HTTPClient):
- def __init__(self, user_agent=DEFAULT_USER_AGENT, debug=False,
timeout=20):
- HTTPClient.__init__(self, user_agent=user_agent, debug=debug,
timeout=timeout)
- def _handle_requests_http_error(self, r):
r.raise_for_status()
- def get_service_version(self):
…
- def get_waveforms(…):
…
Public Methods
Return a semantic version number of the remote service as a string. |
Private Methods
Warning
Private methods are mainly for internal/developer use and their API might change without notice.
- HTTPClient._download(url, params=None, filename=None, data=None, content_type=None)[source]
Download the URL with GET or POST and the chosen parameters.
Will call the
_handle_requests_http_error()
method if the response comes back with an HTTP code other than 200. Returns the response object if successful andfilename
is not given - if given it will save the response to the specified file and returnNone
.By default it will send a GET request - if data is given it will send a POST request.
- Parameters:
url (str) – The URL to download from.
params (dict) – Additional URL parameters.
filename (str or file-like object) – String or file like object. Will download directly to the file. If specified, this function will return nothing.
data (dict, bytes, or file-like object) – If specified, a POST request will be sent with the data in the body of the request.
content_type (str) – Should only be relevant when
data
is specified and thus issuing a POST request. Can be used to set theContent-Type
HTTP header to let the server know what type the body is, e.g."text/plain"
.
- Returns:
The response object assuming
filename
isNone
.- Return type:
- abstract HTTPClient._handle_requests_http_error(r)[source]
Error handling for the HTTP errors.
Method called when the _download() method downloads something with a status code different than 200.
The error codes mean different things for different web services thus this needs to be implemented by every HTTPClient.
- Parameters:
r (
requests.Response
) – The response object resulting in the error.
Special Methods
- HTTPClient.__delattr__(name, /)
Implement delattr(self, name).
- HTTPClient.__dir__()
Default dir() implementation.
- HTTPClient.__eq__(value, /)
Return self==value.
- HTTPClient.__format__(format_spec, /)
Default object formatter.
- HTTPClient.__ge__(value, /)
Return self>=value.
- HTTPClient.__getattribute__(name, /)
Return getattr(self, name).
- HTTPClient.__gt__(value, /)
Return self>value.
- HTTPClient.__hash__()
Return hash(self).
- HTTPClient.__init__(debug=False, timeout=120, user_agent='ObsPy/1.4.1.post0+358.gf5c9534772 (Linux-6.5.0-1025-azure-x86_64-with-glibc2.35, Python 3.9.19)')[source]
- HTTPClient.__init_subclass__()
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
- HTTPClient.__le__(value, /)
Return self<=value.
- HTTPClient.__lt__(value, /)
Return self<value.
- HTTPClient.__ne__(value, /)
Return self!=value.
- HTTPClient.__new__(**kwargs)
- HTTPClient.__reduce__()
Helper for pickle.
- HTTPClient.__reduce_ex__(protocol, /)
Helper for pickle.
- HTTPClient.__repr__()
Return repr(self).
- HTTPClient.__setattr__(name, value, /)
Implement setattr(self, name, value).
- HTTPClient.__sizeof__()
Size of object in memory, in bytes.
- HTTPClient.__str__()
Return str(self).
- HTTPClient.__subclasshook__()
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).