b2sdk.b2http
– thin http client wrapper¶
-
class
b2sdk.b2http.
ResponseContextManager
(response)[source]¶ A context manager that closes a requests.Response when done.
-
class
b2sdk.b2http.
HttpCallback
[source]¶ A callback object that does nothing. Overrides pre_request and/or post_request as desired.
-
pre_request
(method, url, headers)[source]¶ Called before processing an HTTP request.
Raises an exception if this request should not be processed. The exception raised must inherit from B2HttpCallbackPreRequestException.
-
-
class
b2sdk.b2http.
ClockSkewHook
[source]¶
-
class
b2sdk.b2http.
B2Http
(requests_module=None, install_clock_skew_hook=True, user_agent_append=None)[source]¶ A wrapper for the requests module. Provides the operations needed to access B2, and handles retrying when the returned status is 503 Service Unavailable, 429 Too Many Requests, etc.
The operations supported are:
post_json_return_json
post_content_return_json
get_content
The methods that return JSON either return a Python dict or raise a subclass of B2Error. They can be used like this:
try: response_dict = b2_http.post_json_return_json(url, headers, params) ... except B2Error as e: ...
-
TIMEOUT
= 900¶
-
add_callback
(callback)[source]¶ Add a callback that inherits from HttpCallback.
- Parameters
callback (callable) – a callback to be added to a chain
-
post_content_return_json
(url, headers, data, try_count=5, post_params=None)[source]¶ Use like this:
try: response_dict = b2_http.post_content_return_json(url, headers, data) ... except B2Error as e: ...
-
post_json_return_json
(url, headers, params, try_count=5)[source]¶ Use like this:
try: response_dict = b2_http.post_json_return_json(url, headers, params) ... except B2Error as e: ...
-
get_content
(url, headers, try_count=5)[source]¶ Fetches content from a URL.
Use like this:
try: with b2_http.get_content(url, headers) as response: for byte_data in response.iter_content(chunk_size=1024): ... except B2Error as e: ...
- The response object is only guarantee to have:
headers
iter_content()
-
head_content
(url: str, headers: Dict[str, Any], try_count: int = 5) → Dict[str, Any][source]¶ Does a HEAD instead of a GET for the URL. The response’s content is limited to the headers.
Use like this:
try: response_dict = b2_http.head_content(url, headers) ... except B2Error as e: ...
- The response object is only guaranteed to have:
headers