vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

Allowing filtering of the body of a multipart/form-data request

Open bhrutledge opened this issue 5 years ago • 0 comments
trafficstars

In https://github.com/pypa/twine/pull/703, I'm attempting to use VCR to work around flakiness from a file upload to a test server. There was a request not have any Python object serialization in the cassette if at all possible, e.g.:

- request:
    body: !!python/object/new:_io.BytesIO
      state: !!python/tuple
      - !!binary |
        LS0xYzcwMTIzOGVkZmM0ZjRhYjZkMjU0NDU1ZjkxZGU1Mg0KQ29udGVudC1EaXNwb3NpdGlvbjog
        Zm9ybS1kYXRhOyBuYW1lPSJuYW1lIg0KDQp0d2luZS1zYW1wbGVwcm9qZWN0DQotLTFjNzAxMjM4

It looks like VCR.py treats BytesIO as a special case when applying filters:

https://github.com/kevin1024/vcrpy/blob/4a8e80ee3e288c61a85a90d7f13c83d9e9a4db2e/vcr/filters.py#L86

The closest I could get was setting request.body to None via custom request filtering, but that still results in:

- request:
    body: !!python/object/new:_io.BytesIO
      state: !!python/tuple
      - !!binary ""

Any suggestions?

bhrutledge avatar Oct 03 '20 18:10 bhrutledge