Adds support for the Refresh header in requests. Check out the README for more info.
Project description
requests_header_refresh
Description
This Python module provides a function to handle HTTP refresh headers in the requests
library. It parses the refresh header, extracts or infers the refresh time and URL, and makes a subsequent request to the refresh URL if the refresh time is in a valid range. It also supports a refresh timeout to ignore the refresh if the refresh time is greater than the timeout.
Installation
You can use this module by importing it in your Python script. Make sure to have the requests-header-refresh
library installed in your environment. If not, you can install it using pip:
pip install requests-header-refresh
You will also need the requests library to use this package.
Usage
First, import the necessary functions and classes:
import requests
from requests_header_refresh import create_hook
Then, create a session and a refresh handler with a timeout of 5 seconds:
session = requests.Session()
refresh_hook = create_hook(refresh_timeout=5)
Add the handler as a response hook:
session.hooks = {'response': [refresh_hook]}
Finally, make a request:
response = session.get(url)
In this example, refresh_hook
will ignore the refresh if the refresh time is greater than 5 seconds. Replace url
with the actual URL you want to make a request to. Also, adjust the refresh_timeout
based on your needs.
The hook could also be used for a single request instead of entire session:
response = requests.get(url, hooks={'response': [refresh_hook]})
Contributing
Contributions are welcome.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for requests_header_refresh-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9832571aff80434587a379c18877e2e2ad37d703f593a816e7633de701b694d |
|
MD5 | 1752fc7e06d848f411adbaaf082226cd |
|
BLAKE2b-256 | eefa011fb3c169b72e91df95ac8225f5faf908c5f0b3d65dfa89e49af7d27e7d |
Hashes for requests_header_refresh-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4056b83249d3789e0669bd205beb47126faefabfaa5dbcd25e9250f2cc29fba |
|
MD5 | 12fbe1f5da59a3387e158333e553502e |
|
BLAKE2b-256 | 7602be5e8b5cf964e9d3c6ff0d601536c79ede57ba38db83bca0df0005e4d1dc |