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

multipart/form-data and a generator... #6826

Closed
steve-osfda opened this issue Nov 13, 2024 · 1 comment
Closed

multipart/form-data and a generator... #6826

steve-osfda opened this issue Nov 13, 2024 · 1 comment
Labels
actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug

Comments

@steve-osfda
Copy link

I used a generator as an argument to data for Content-Type application/json, and that worked fine.

The problem now is that I need to do this for multipart/form-data, and it appears to not support a generator.

  • I tried files={'content': my_generator_func()} and got: a bytes-like object is required, not 'generator'; so it looks like it would have accepted a file descriptor, but not a generator.

  • I then tried a generator for the data argument, and set the files argument to a form name and value: files={'encoding': (None, 'base64')} [I read you have to use the files argument to get requests to do multipart/form-data] For that I get the error "Streamed bodies and files are mutually exclusive".

  • Just in case, I tried it different ways setting a header for Content-Type multipart/form-data, both with and without it [I had read that setting it yourself can mess up requests.] If I omitted it, it complained it was missing; and if I included it, I got the errors previously specified.

Is it possible to furnish a generator for multipart/form-data? If I have to, I will dump the stream into a file and pass a descriptor to the files argument; but seems that you would have furnished a way to use a generator since it is supported for Content-Type application/json

@steve-osfda steve-osfda added actions/autoclose-qa Used for automation to auto-close an issue Question/Not a bug labels Nov 13, 2024
Copy link

As described in the template, we won't be able to answer questions on this issue tracker. Please use Stack Overflow

@github-actions github-actions bot locked as off-topic and limited conversation to collaborators Nov 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

1 participant