Message381658
urllib is a high level API on top of http.client. It wraps and uses http.client internally. urllib does not accept invalid protocol identifiers either:
>>> urllib.request.urlopen('http://localhost:8080')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib64/python3.8/urllib/request.py", line 525, in open
response = self._open(req, data)
File "/usr/lib64/python3.8/urllib/request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "/usr/lib64/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib64/python3.8/urllib/request.py", line 1379, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/lib64/python3.8/urllib/request.py", line 1354, in do_open
r = h.getresponse()
File "/usr/lib64/python3.8/http/client.py", line 1347, in getresponse
response.begin()
File "/usr/lib64/python3.8/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python3.8/http/client.py", line 289, in _read_status
raise BadStatusLine(line)
http.client.BadStatusLine: Http/1.1 200 OK
curl is more forgiving but does not recognize "Http/1.1" as a valid HTTP/1.1 header either. Instead it assumes that any non-valid header means HTTP/1.0.
$ curl -v http://localhost:8080
* Trying ::1:8080...
* connect to ::1 port 8080 failed: Connection refused
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.69.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< Http/1.1 200 OK
< Server: BaseHTTP/0.6 Python/3.8.6
< Date: Mon, 23 Nov 2020 09:10:38 GMT
< Content-Type: text/plain
<
* Closing connection 0
I'm against changing the behavior of http.client. |
|
Date |
User |
Action |
Args |
2020-11-23 09:22:54 | christian.heimes | set | recipients:
+ christian.heimes, eric.smith, sicarius |
2020-11-23 09:22:54 | christian.heimes | set | messageid: <1606123374.76.0.6347425254.issue42432@roundup.psfhosted.org> |
2020-11-23 09:22:54 | christian.heimes | link | issue42432 messages |
2020-11-23 09:22:54 | christian.heimes | create | |
|