Skip to content

Commit 345f28f

Browse files
committed
Merge pull request #28 from trustpilot/fix-403-forbidden-responses-not-authenticating
Authenticate on 401 _and_ 403 responses
2 parents ac25d66 + 0742ae1 commit 345f28f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ _(for **full usage documentation** checkout [docs](https://github.com/trustpilot
2828
```python
2929
from trustpilot import client
3030
client.default_session.setup(
31-
api_host="https://api.trustpilot.com"
32-
api_key="YOUR_API_KEY"
31+
api_host="https://api.trustpilot.com",
32+
api_key="YOUR_API_KEY",
3333
)
3434
response = client.get("/foo/bar")
3535
status_code = response.status_code

trustpilot/async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ async def request_context_manager(self, method, url, *args, **kwargs):
8888
async with aiohttp.ClientSession(headers=self.headers) as session:
8989
http_method = getattr(session, method)
9090
async with http_method(cleaned_url, *args, **kwargs) as response:
91-
if response.status == 401:
91+
if response.status in (401, 403):
9292
authenticate_and_retry = True
9393
else:
9494
yield response

trustpilot/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _post_request_callback(self, response, *args, **kwargs):
112112
req = response.request
113113
retry = getattr(req, "authentication_retry", True)
114114

115-
if retry and response.status_code == requests.codes.unauthorized:
115+
if retry and response.status_code in (requests.codes.unauthorized, requests.codes.forbidden):
116116
logger.debug(
117117
{"message": "reauthenticating and retrying once", "url": req.url}
118118
)

0 commit comments

Comments
 (0)