dicogis.utils.http package¶
HTTP clients: requests or the network stack of QGIS, behind a common contract.
The backend is picked from the DICOGIS_HTTP_BACKEND environment variable, on the same model as DICOGIS_QT_API:
auto (default): the network stack of QGIS when running inside QGIS, i.e. a QgsApplication is running, requests otherwise.
requests: always requests.
qgis: always the network stack of QGIS.
- class dicogis.utils.http.HttpClient(*args, **kwargs)¶
Bases:
ProtocolWhat the publication code needs to reach a catalog.
Implementations are stateless, cookies included: what a request sends is what its caller gives. Each backend otherwise has its own cookie jar, which overrides the Cookie header once it holds a cookie for the host.
- __init__(*args, **kwargs)¶
- request(method, url, *, params=None, headers=None, data=None, timeout=None)¶
Send a request and wait for its response, redirections being followed.
- Parameters:
- Raises:
HttpTransportError – if no response was received
- Return type:
- Returns:
response, whatever its status code
- exception dicogis.utils.http.HttpError¶
Bases:
ExceptionBase class of the errors raised by the HTTP clients.
- class dicogis.utils.http.HttpResponse(status_code, headers=<factory>, cookies=<factory>, content=b'', url='')¶
Bases:
objectAn HTTP response, whatever the backend which received it.
- status_code¶
HTTP status code
- headers¶
headers, names in lowercase
- cookies¶
cookies set by this very response, by name
- content¶
body
- url¶
final URL of the request
- __init__(status_code, headers=<factory>, cookies=<factory>, content=b'', url='')¶
- raise_for_status()¶
Raise an error if the response tells one.
- Raises:
HttpStatusError – if the status code is 400 or above
- Return type:
- exception dicogis.utils.http.HttpStatusError(response)¶
Bases:
HttpErrorAn HTTP response was received, telling an error.
- response¶
the response at stake
- __init__(response)¶
Build the error from its response.
- Parameters:
response (
HttpResponse) – the response at stake
- exception dicogis.utils.http.HttpTransportError¶
Bases:
HttpErrorNo HTTP response was received: connection refused, timeout, canceled…
- dicogis.utils.http.get_http_client(backend=None, *, authcfg=None, feedback=None)¶
Build the HTTP client of the running environment.
- Parameters:
backend (str | None) – see resolve_http_backend()
authcfg (str | None) – identifier of a configuration of the QGIS authentication manager
feedback (QgsFeedback | None) – interrupts the running request when canceled (QGIS backend)
- Raises:
ValueError – if the backend is unknown, or authcfg is given while QGIS isn’t used
- Return type:
HttpClient
- Returns:
HTTP client
- dicogis.utils.http.parse_set_cookie(header_value)¶
Read the cookies of Set-Cookie headers merged on several lines, as Qt does.
- dicogis.utils.http.resolve_http_backend(requested=None)¶
Determine which HTTP backend to use.
- Parameters:
requested (
str|None) – one of HTTP_BACKENDS, case-insensitive. Defaults to the value of the DICOGIS_HTTP_BACKEND environment variable, or auto if unset.- Raises:
ValueError – if the requested backend is unknown
- Returns:
requests or qgis
- Return type:
the backend to use
Submodules¶
- dicogis.utils.http.backend_qgis module
- dicogis.utils.http.backend_requests module
- dicogis.utils.http.client module
HttpClientHttpErrorHttpResponseHttpResponse.status_codeHttpResponse.headersHttpResponse.cookiesHttpResponse.contentHttpResponse.urlHttpResponse.__init__()HttpResponse.contentHttpResponse.cookiesHttpResponse.headersHttpResponse.json()HttpResponse.raise_for_status()HttpResponse.status_codeHttpResponse.textHttpResponse.url
HttpStatusErrorHttpTransportErrorparse_set_cookie()