requests / toolbelt

A toolbelt of useful classes and functions to be used with python-requests
https://toolbelt.readthedocs.org
Other
1k stars 186 forks source link

How do you reset the multipartencoder? #363

Closed achapkowski closed 1 year ago

achapkowski commented 1 year ago

I have a situation where I use the MultipartEncoder with IWA. During the handshake process, the encoder's payload get read, but on the next send(), no payload is sent, causing a 408. Is there a way to reset the encoder's seek position for each field?

sigmavirus24 commented 1 year ago

I don't know what IWA is or why that might be relevant. It's also surprising that data is being sent during the handshake. That's a troubling bug in http.client if true.

Given the flexibility and constants of the encoder there is no method to reset it or its fields. There's also no appetite to do so.

It allows for a file like object which could be a response or stdin which are not rewindable. It doesn't try to detect that either. Finally it is designed to keep as little days in active memory as possible so caching the data wouldn't be an option.

achapkowski commented 1 year ago

Sorry for the acronym, I am using this: https://en.wikipedia.org/wiki/Integrated_Windows_Authentication

Basically during the handshake it does 3 calls back and forth between the server and the client to get the authentication piece down.

The fields property seems to persist the data at some levels, but not all of it. Could I go into each part and set seek(0) on the IO objects?

sigmavirus24 commented 1 year ago

Could I go into each part and set seek(0) on the IO objects?

You could certainly see if that works for your use case. That's not something I've ever tested the encoder for though so there's no guarantees of correctness.

achapkowski commented 1 year ago

Didn't work, I ended up just passing the payload into the file parameter to get it to work.