Skip to content

Commit 67525c7

Browse files
committed
Post final QA fixes
1 parent 0f1d695 commit 67525c7

File tree

6 files changed

+30
-38
lines changed

6 files changed

+30
-38
lines changed

python-requests/custom_token_auth.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class TokenAuth(AuthBase):
88
def __init__(self, token):
99
self.token = token
1010

11-
def __call__(self, r):
11+
def __call__(self, request):
1212
"""Attach an API token to the Authorization header."""
13-
r.headers["Authorization"] = f"Bearer {self.token}"
14-
return r
13+
request.headers["Authorization"] = f"Bearer {self.token}"
14+
return request
1515

1616

1717
if __name__ == "__main__":

python-requests/requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
certifi==2024.2.2
2-
charset-normalizer==3.3.2
3-
idna==3.6
4-
requests==2.31.0
5-
urllib3==2.2.1
1+
certifi==2025.7.14
2+
charset-normalizer==3.4.2
3+
idna==3.10
4+
requests==2.32.4
5+
urllib3==2.5.0

python-requests/retry_thrice.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@
77

88
logging.basicConfig(level=logging.DEBUG)
99

10-
retries = Retry(total=3, status_forcelist=[404])
10+
retry_strategy = Retry(total=3, status_forcelist=[404])
11+
github_adapter = HTTPAdapter(max_retries=retry_strategy)
1112

12-
github_adapter = HTTPAdapter(max_retries=retries)
13-
14-
session = requests.Session()
15-
16-
session.mount("https://api.github.com", github_adapter)
17-
18-
try:
19-
response = session.get("https://api.github.com/")
20-
print(response.status_code)
21-
response = session.get("https://api.github.com/invalid")
22-
print(response.status_code)
23-
except RetryError as err:
24-
print(f"Error: {err}")
25-
finally:
26-
session.close()
13+
with requests.Session() as session:
14+
session.mount("https://api.github.com", github_adapter)
15+
try:
16+
response = session.get("https://api.github.com/")
17+
print(response.status_code)
18+
response = session.get("https://api.github.com/invalid")
19+
print(response.status_code)
20+
except RetryError as err:
21+
print(f"Error: {err}")

python-requests/retry_twice.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import requests
22
from requests.adapters import HTTPAdapter
33
from requests.exceptions import RetryError
4+
from urllib3.util.retry import Retry
45

5-
github_adapter = HTTPAdapter(max_retries=2)
6+
retry_strategy = Retry(total=2, status_forcelist=[429, 500, 502, 503, 504])
7+
github_adapter = HTTPAdapter(max_retries=retry_strategy)
68

7-
session = requests.Session()
8-
9-
session.mount("https://api.github.com", github_adapter)
10-
11-
try:
12-
response = session.get("https://api.github.com/")
13-
except RetryError as err:
14-
print(f"Error: {err}")
15-
finally:
16-
session.close()
9+
with requests.Session() as session:
10+
session.mount("https://api.github.com", github_adapter)
11+
try:
12+
response = session.get("https://api.github.com/")
13+
except RetryError as err:
14+
print(f"Error: {err}")

python-requests/search_popular_repos.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@
1212
for repo in popular_repositories[:3]:
1313
print(f"Name: {repo['name']}")
1414
print(f"Description: {repo['description']}")
15-
print(f"Stars: {repo['stargazers_count']}")
16-
print()
15+
print(f"Stars: {repo['stargazers_count']}\n")

python-requests/text_matches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
headers={"Accept": "application/vnd.github.text-match+json"},
77
)
88

9-
# View the new `text-matches` list which provides information
9+
# View the new 'text_matches' list which provides information
1010
# about your search term within the results.
1111
json_response = response.json()
1212
first_repository = json_response["items"][0]

0 commit comments

Comments
 (0)