Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to send async generator as data argument of request method? #6595

Closed
EverettDunamu opened this issue Dec 1, 2023 · 1 comment
Labels
actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug

Comments

@EverettDunamu
Copy link

EverettDunamu commented Dec 1, 2023

I'm using requests module in Python and I want to send data in request streaming way. so I applied chunked-encoded request according to this document.

However, the data to send is provided with another async method. Honestly speaking, I also use Sanic framework, and I read the stream data from await sanic.request.stream.read() and I want to relay the streaming data to request method of requests module.

async def generate_from_sanic_request(request):
  while True:
    chunk = await request.stream.read()
    if chunk is None:
      break
    yield chunk

...
requests.request(
  method="POST",
  url="my-own-url",
  data=generate_from_sanic_request, # here is the point of this question.
)
...

The document says that I can use the non-async generator function as the data argument. However, when I use an async generator there, requests.request cannot handle the generator.

I want to do this in a memory-efficient way, so I want to bypass the received streaming request body to requests.request method in one-by-one way.

Can I get any help to solve this problem?

Thanks in advance.

@EverettDunamu EverettDunamu added actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug labels Dec 1, 2023
@sigmavirus24
Copy link
Contributor

It is not possible to use an async generator with requests. For help with your code, please use StackOverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug
Projects
None yet
Development

No branches or pull requests

2 participants