aiohttp client and JWT authorization header problem #6523
-
I'm having problems setting the "Authorization" header in aiohttp. I need to make a request to an authenticated API using JWT but when I add the token manually to the header, aiohttp returns the following errors: ValueError: [TypeError("'URL' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')] The JWT token I have to send in the header is quite long so I guess there is some limitation for the size because if I modify it to use a shorter (and fake) one, the request is sent even though the "Authorization" header is omitted. I guess this has to do with the following warning in the documentation:
I couldn't find anything in the docs or the repo to backup these facts so I don't know how to proceed. The following code was used to make the request: try:
# Using fake URL and headers as an example
url = "https://myapi.com/get-data"
headers = {"Authorization": "Bearer eyJ0eXniOiJ2V1QiLCJhcGciOiJS4zI1NiJ9..."}
async with self.session.get(url, headers=headers) as response:
await response.read()
return response
except aiohttp.ClientConnectionError as e:
message = f"Connection error: {e}"
raise RequestErrorException(url=url, detail=message)
except Exception as e:
message = f"Data error: {e}"
raise RequestErrorException(url=url, detail=message) And here is the traceback:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Every line of your traceback comes from fastapi... I doubt anybody here is likely to be able to help when the traceback doesn't seem to have anything to do with aiohttp, except that somewhere the |
Beta Was this translation helpful? Give feedback.
Every line of your traceback comes from fastapi...
I doubt anybody here is likely to be able to help when the traceback doesn't seem to have anything to do with aiohttp, except that somewhere the
URL
object has ended up in the fastapi code.