koenvo / pyodide-http

Provides patches for widely used http libraries to make them work in Pyodide environments like JupyterLite
MIT License
77 stars 14 forks source link

BadStatusLine: HTTP/1.1 0 in urlopen #41

Open vnmabus opened 10 months ago

vnmabus commented 10 months ago

When executing urlopen (after patching) in a JupyterLite kernel, I get the following error.

---------------------------------------------------------------------------
BadStatusLine                             Traceback (most recent call last)
Cell In[5], line 1
----> 1 with urlopen(pkg_url) as package:
      2     with tarfile.open(fileobj=package, mode="r|gz") as package_tar:
      3         for member in package_tar:

File /lib/python3.11/site-packages/pyodide_http/_urllib.py:53, in urlopen(url, *args, **kwargs)
     41 response_data = (
     42     b"HTTP/1.1 "
     43     + str(resp.status_code).encode("ascii")
   (...)
     49     + resp.body
     50 )
     52 response = HTTPResponse(FakeSock(response_data))
---> 53 response.begin()
     54 return response

File /lib/python311.zip/http/client.py:318, in HTTPResponse.begin(self)
    316 # read until we get a non-100 response
    317 while True:
--> 318     version, status, reason = self._read_status()
    319     if status != CONTINUE:
    320         break

File /lib/python311.zip/http/client.py:306, in HTTPResponse._read_status(self)
    304     status = int(status)
    305     if status < 100 or status > 999:
--> 306         raise BadStatusLine(line)
    307 except ValueError:
    308     raise BadStatusLine(line)

BadStatusLine: HTTP/1.1 0
koenvo commented 9 months ago

This is probably related to https://github.com/koenvo/pyodide-http/issues/26

The status 0 response (HTTP/1.1 0) often indicates the request failed. Could you check the network tab?