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 maximum refresh to ignore the refresh if the refresh time is greater than a specified number of seconds.
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(max_refresh=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 max_refresh 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file requests_header_refresh-1.0.5.tar.gz.
File metadata
- Download URL: requests_header_refresh-1.0.5.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a279f37d1e61791137769170bf0b6f4106436a98339c85c13b9dd490ecbdbdf
|
|
| MD5 |
108f2045c1c4f1ecd8927ff886a5d134
|
|
| BLAKE2b-256 |
fecc829b378e80e47b32a42eebb961f4364297e9dc12dce580f1e7b584f4a09d
|
File details
Details for the file requests_header_refresh-1.0.5-py3-none-any.whl.
File metadata
- Download URL: requests_header_refresh-1.0.5-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d24a539afa961640a70db4c6b340a70b6109a625862afc1e98c8cf8e1358e8c8
|
|
| MD5 |
1ea5bd643a456fbbca33536361b7490a
|
|
| BLAKE2b-256 |
a223a0294553fe7e98197308737a9a98d926236efbff28246ac73ffae244ba2f
|