-
Hi, I'm using aiohttp to make async http requests, however I can't figure out how to get a response from the server when a request returns a 4XX error. async def login(self, username: str, password: str) -> None:
async with aiohttp.ClientSession(headers=self._headers) as session:
self._session = session
route = self._route + "/api/login"
data = {
"grant_type": "password",
"client_id": "ANDR",
"username": username,
"password": password
}
async with session.post(route, data=data, headers=self._headers) as resp:
if resp.ok:
resp_json = await resp.json()
self._headers['Authorization'] = 'Bearer ' + json['resp_json']
else:
resp_json = await resp.json()
raise InvalidGrant(response) When the response returns a 2XX error (aka when |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I remember fixing this with #5407 async with session.post(route, data=data, headers=self._headers) as resp:
resp_json = await resp.json()
if resp.ok:
self._headers['Authorization'] = 'Bearer ' + json['resp_json']
else:
raise InvalidGrant(response) |
Beta Was this translation helpful? Give feedback.
I remember fixing this with #5407
does it work fine when you change your code as follows?