-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
When using the python requests library, if one sets the body (data) to a file-like object, such as io.BytesIO or io.StringIO, the body becomes something like <_io.BytesIO object at 0x1550d50> when using pyodide-http, as opposed to the actual contents of the file-like object.
Below is a very hacky fix for this problem:
diff --git a/pyodide_http/_core.py b/pyodide_http/_core.py
index 1cb711d..e8de6b9 100644
--- a/pyodide_http/_core.py
+++ b/pyodide_http/_core.py
@@ -118,7 +118,13 @@ def send(request: Request, stream: bool = False) -> Response:
if name.lower() not in HEADERS_TO_IGNORE:
xhr.setRequestHeader(name, value)
- xhr.send(to_js(request.body))
+ body = request.body
+
+ if hasattr(body, 'read'):
+ body = body.read()
+
+ xhr.send(to_js(body))
+ #xhr.send(to_js(request.body))
headers = dict(Parser().parsestr(xhr.getAllResponseHeaders()))
I suppose that perhaps a stream method could be used with a file-like object? Any ideas on how to best solve this problem?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels