Open kfot opened 6 months ago
can you please provide a minimal reproducible ?
Feeding multipart requests that way is fine but hangs the responses (as the iterators are not consumed and file.tell()
keeps pointing to 0).
def chunk_file(f, chunk_size, chunk_limit):
chunks_read = 0
while chunks_read < chunk_limit:
chunk = f.read(chunk_size)
if chunk == b"":
break
yield chunk
chunks_read += chunk_size
import os
file_size = os.stat(filepath).st_size
with open(filepath, "rb") as f:
while f.tell() < file_size:
data_chunk = chunk_file(
f,
chunk_size=4*1024,
chunk_limit=8*1024,
)
...
requests.post(url, headers, data=data_chunk)
Avoiding the .tell()
in the loop condition (like for _ in range(int(math.ceil(file_size / chunk_limit))):
) worked pretty well but I still wonder to what extent the requests
behavior should be mockable by the responses
.
Describe the bug
Hi, I am developing some python code utilizing mulipart/form-data headers for uploading a file. When I try to mock the endpoint response with the following code, then it hangs.
Responses: 0.25.0 Python: 3.11
Additional context
Once I will add a multipart matcher, I can get an error stating that the iterator does not match the data (as the generator is just an object in the memory).
Version of
responses
0.25.0
Steps to Reproduce
Add an generator to be consumed by the request.
Expected Result
Code using responses does not hang anymore.
Actual Result
Tests using responses hang.