gufo.http.sync_client¶
Synchronous client.
HttpClient
¶
Bases: object
Synchronous HTTP client.
Attributes:
Name | Type | Description |
---|---|---|
headers |
Optional[Dict[str, bytes]]
|
Headers to be added to every request. Used in subclasses. |
user_agent |
Default user agent. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_redirects |
Optional[int]
|
Set up redirects policy:
|
MAX_REDIRECTS
|
compression |
Optional[int]
|
Acceptable compression methods,
must be a combination of |
DEFLATE | GZIP | BROTLI
|
validate_cert |
bool
|
Set to |
True
|
connect_timeout |
float
|
Timeout to establish connection, in seconds. |
DEFAULT_CONNECT_TIMEOUT
|
timeout |
float
|
Request timeout, in seconds. |
DEFAULT_TIMEOUT
|
auth |
Optional[AuthBase]
|
Authentication settings. |
None
|
proxy |
Optional[List[Proxy]]
|
Optional list of Proxy istances. |
None
|
__enter__()
¶
__exit__(exc_type, exc_val, exc_tb)
¶
Context manager exit.
delete(url, /, headers=None)
¶
Send HTTP DELETE request and receive a response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Request url, use |
required |
headers |
Optional[Dict[str, bytes]]
|
Optional request headers. |
None
|
Returns:
Type | Description |
---|---|
Response
|
Response instance. |
Raises:
Type | Description |
---|---|
TimeoutError
|
on timeouts. |
ConnectionError
|
when failed to establish connection. |
RedirectError
|
when redirects limit reached. |
RequestError
|
on other errors related with request processing. |
get(url, /, headers=None)
¶
Send HTTP GET request and receive a response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Request url |
required |
headers |
Optional[Dict[str, bytes]]
|
Optional request headers |
None
|
Returns:
Type | Description |
---|---|
Response
|
Response instance. |
Raises:
Type | Description |
---|---|
TimeoutError
|
on timeouts. |
ConnectionError
|
when failed to establish connection. |
RedirectError
|
when redirects limit reached. |
RequestError
|
on other errors related with request processing. |
head(url, /, headers=None)
¶
Send HTTP HEAD request and receive a response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Request url |
required |
headers |
Optional[Dict[str, bytes]]
|
Optional request headers |
None
|
Returns:
Type | Description |
---|---|
Response
|
Response instance. |
Raises:
Type | Description |
---|---|
TimeoutError
|
on timeouts. |
ConnectionError
|
when failed to establish connection. |
RedirectError
|
when redirects limit reached. |
RequestError
|
on other errors related with request processing. |
options(url, /, headers=None)
¶
Send HTTP OPTIONS request and receive a response.
Usually returns 204 No content
response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Request url, use |
required |
headers |
Optional[Dict[str, bytes]]
|
Optional request headers. |
None
|
Returns:
Type | Description |
---|---|
Response
|
Response instance. |
Raises:
Type | Description |
---|---|
TimeoutError
|
on timeouts. |
ConnectionError
|
when failed to establish connection. |
RedirectError
|
when redirects limit reached. |
RequestError
|
on other errors related with request processing. |
patch(url, body, /, headers=None)
¶
Send HTTP PATCH request and receive a response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Request url, use |
required |
body |
bytes
|
Request body. |
required |
headers |
Optional[Dict[str, bytes]]
|
Optional request headers. |
None
|
Returns:
Type | Description |
---|---|
Response
|
Response instance. |
Raises:
Type | Description |
---|---|
TimeoutError
|
on timeouts. |
ConnectionError
|
when failed to establish connection. |
RedirectError
|
when redirects limit reached. |
RequestError
|
on other errors related with request processing. |
post(url, body, /, headers=None)
¶
Send HTTP POST request and receive a response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Request url, use |
required |
body |
bytes
|
Request body. |
required |
headers |
Optional[Dict[str, bytes]]
|
Optional request headers. |
None
|
Returns:
Type | Description |
---|---|
Response
|
Response instance. |
Raises:
Type | Description |
---|---|
TimeoutError
|
on timeouts. |
ConnectionError
|
when failed to establish connection. |
RedirectError
|
when redirects limit reached. |
RequestError
|
on other errors related with request processing. |
put(url, body, /, headers=None)
¶
Send HTTP PUT request and receive a response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
Request url, use |
required |
body |
bytes
|
Request body. |
required |
headers |
Optional[Dict[str, bytes]]
|
Optional request headers. |
None
|
Returns:
Type | Description |
---|---|
Response
|
Response instance. |
request(method, url, /, body=None, headers=None)
¶
Send HTTP request and receive a response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method |
RequestMethod
|
Request method |
required |
url |
str
|
Request url |
required |
body |
Optional[bytes]
|
Request body |
None
|
headers |
Optional[Dict[str, bytes]]
|
Optional request headers |
None
|
Returns:
Type | Description |
---|---|
Response
|
Response instance. |
Raises:
Type | Description |
---|---|
TimeoutError
|
on timeouts. |
ConnectionError
|
when failed to establish connection. |
RedirectError
|
when redirects limit reached. |
RequestError
|
on other errors related with request processing. |