Why does stream not return a file-like object (this breaks compatibility) #2296
-
In my company we use mostly httpx in our projects to do sync and async calls to our and other apis, but recently we ran into an issue, which (imo) could (and maybe should?) be solved:
Sure, I could write a proxy object to do this, but as this is quit a low level functionality it feels like that it's something this package should directly provide. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 12 replies
-
I don't quite understand the question. Perhaps providing an example of what you mean would help work through this? The with client.stream("GET", "https://www.example.com") as response:
... You can use |
Beta Was this translation helpful? Give feedback.
-
@tomchristie Was this feature request/ question dropped? Seems to me there is still no work around for this |
Beta Was this translation helpful? Give feedback.
-
Is the following code what you want with httpx.stream("GET", "https://example.com/") as response:
raw_stream = response.extensions["network_stream"]
print(raw_stream.read(2))
# b'\x1f\x8b'
print(requests.get("https://example.com/", stream=True).raw.read(2))
# b'\x1f\x8b' |
Beta Was this translation helpful? Give feedback.
-
I hit a similar problem but with tarfile while trying to move some code from requests to httpx. This is what my requests code looks like:
I did try the "network_stream" approach but I couldn't get it to work reliably. Possibly I was doing it wrong:
I want to avoid writing the tarfiles to a temporary file as they are a few GiB in size. |
Beta Was this translation helpful? Give feedback.
Is the following code what you want