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
Requests containing files cannot be replayed. #64
Comments
So there's going to be a severe layers violation here if we try to do that. The preparation of that multipart body happens well before the betamax adapter sees it. That stuff happens before we even get the data. There's no way we as a library can do this and I'm not certain what the best fix is. As I see it, we have two options:
Personally I'm leaning towards 2. Thoughts @bboe? |
Note: Currently the MultipartDecoder is designed to work with responses, but it can just as easily work with request objects. |
I suppose #2 is the way to go if we cannot change the multipart boundary. My other option would be to get requests to accept specifying the multipart boundary (urlib3 does, but not requests) so that I can set it static (there's not reason to change the boundary per request). I started down this former path (not actual decoding though) and ran into another set of encoding errors between versions of python as the request in memory is in binary format. |
So this isn't something people frequently ask for. The "blessed" way of doing that is with the
You mean the request stored by Betamax or something else? I suspect that the MultipartDecoder will be able to handle this. I haven't used it extensively, but it appeared to be very robust and well built. Since this seems amenable, I'll prioritize this. I'm running the PSF's elections next week so I may not be able to attend to this until after I kick those off. By the @bboe, if you're not already a contributing member of the PSF, you should become one. It's free! |
@bboe I started working on this in betamaxpy/betamax_matchers@6155015 |
Awesome! Thanks @sigmavirus24 |
So I have a question for you @bboe: If you take a look at betamaxpy/betamax_matchers@2199dea, you'll see that a first implementation of this makes it fairly... naïve. Can you point me to how you're using I haven't tested any of this, but if you can provide early feedback that'd be awesome. |
It's a little complicated but here goes. The following are the tests that I would like to run. They are commented out currently because they are not replayable. Also the test methods should be decorated with PRAW uses This prepared request can be used in one of two ways. Most commonly it is sent to a rate limit handler that ensures requests are only made within the API's time limits: The second way is to permit distributed rate limit handling. In that case, the prepared request is serialized and transmitted to another process that handles the request:
I hope that helps some. I really appreciate you looking into it. I should have some time this weekend to be of any assistance. |
So looking at the |
Oh and speaking of a betamax decorator, we've had a similar request here: #61 |
To make your testing easier @bboe I have released 🍺 Cheers! |
Thank you! I will look at it this weekend. I appreciate your efforts 👍 |
When specifying files via
files=[...]
requests results in choosing a differentmultipart_boundary
each time, thus making it quite difficult to match. There also appear to be some issues with cassettes and binary data for body matching.Perhaps when using the betamax adapter, the
multipart_boundary
can be fixed to a constant value rather than auuid
that requests uses.The text was updated successfully, but these errors were encountered: