urllib3 Retry and Response Hooks (Duplicates #4514)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 54.3k
- Forks
- 10.4k
- Avg merge
- 16h 43m
- Merged PRs (30d)
- 3
Description
Given you have a session, and have successfully attached the auth class and the response hooks accordingly; although you'd like to add the Retry class into the picture from urllib3.
Expected Result
I'd expect the response hooks to be honoured - at the very least on the first response (not retry).
Actual Result
The response hooks are ignored completely.
Reproduction Steps
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
retry = Retry(total=1, read=1, connect=1, backoff_factor=0.5,
status_forcelist=(401, 500))
adapter = HTTPAdapter(max_retries=retry)
session = requests.Session()
session.hooks = {'response': response_hook}
session.mount('http://', adapter)
session.mount('https://', adapter)
def response_hook(response, *args, **kwargs):
"""
Response hook
:param response:
:return:
"""
if response.status_code == requests.codes.unauthorized:
print('Your logic here')
System Information
Python version: 3.5
Requests version: 2.11.0
OS: Ubuntu 16.04
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the behavior with Session, HTTPAdapter, Retry, and the response hook shown in the issue. Read duplicate issue #4514 and trace how retries relate to response hooks. Add a regression test for the expected first-response hook behavior; done when the hook is honored despite the configured Retry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100