encode / requests-async

async-await support for `requests`. ✨ 🍰 ✨

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sessions "Cannot access .content on a streaming response"

odysseusmax opened this issue · comments

When requesting a stream request with sessions, requests_async.exceptions.ContentNotAvailable: Cannot access .content on a streaming response occours. Works just fine if stream=False

Code used

async with requests.Session() as session:
        r = await session.get(url,  params=params, stream=True, verify=False)
        for key,value in r.headers.items():
            print(key, ' : ',value)

Error

Traceback (most recent call last):
   File "/app/.heroku/python/lib/python3.7/site-packages/pyrogram/client/ext/dispatcher.py", line 155, in update_worker
     await handler.callback(self.client, *args)
   File "main.py", line 206, in text
     result = await download(c, m, message, snt.message_id)
   File "/app/downlods.py", line 24, in download
     ext = await gdrive_dl(c, m, url, mid, filename)
   File "/app/downlods.py", line 84, in gdrive_dl
     r = await session.get(url, params=params, stream=True, verify=False)
   File "/app/.heroku/python/lib/python3.7/site-packages/requests_async/sessions.py", line 85, in get
     return await self.request("GET", url, **kwargs)
   File "/app/.heroku/python/lib/python3.7/site-packages/requests_async/sessions.py", line 79, in request
     resp = await self.send(prep, **send_kwargs)
   File "/app/.heroku/python/lib/python3.7/site-packages/requests_async/sessions.py", line 157, in send
     async for resp in self.resolve_redirects(r, request, **kwargs):
   File "/app/.heroku/python/lib/python3.7/site-packages/requests_async/sessions.py", line 209, in resolve_redirects
     resp.content  # Consume socket so it can be released
   File "/app/.heroku/python/lib/python3.7/site-packages/requests_async/models.py", line 25, in content
     raise ContentNotAvailable("Cannot access .content on a streaming response")
 requests_async.exceptions.ContentNotAvailable: Cannot access .content on a streaming response

Right - apologies - few teething issues with the switch to httpcore, which allows us to get streaming requests/responses, connection pooling, etc...

I've release requests-async 0.4, which resolves this issue.