This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2011年08月28日 19:19 by shubhojeet.ghosh, last changed 2022年04月11日 14:57 by admin.
| Messages (8) | |||
|---|---|---|---|
| msg143120 - (view) | Author: Shubhojeet Ghosh (shubhojeet.ghosh) | Date: 2011年08月28日 19:19 | |
There seems to be an issue with urllib2 The headers defined does not match with the physical data packet (from wireshark). Other header parameters such as User Agent, cookie works fine. Here is an example of a failure: Python Code: import urllib2 url = "http://www.python.org" req = urllib2.Request(url) req.add_header('Connection',"keep-alive") u = urllib2.urlopen(req) Wireshark: GET / HTTP/1.1 Accept-Encoding: identity Connection: close Host: www.python.org User-Agent: Python-urllib/2.6 |
|||
| msg170476 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2012年09月14日 13:28 | |
I've closed issue 15943 as a duplicate of this one. As I said there, I'm not sure that we (can?) support keep-alive in urllib, though we do in httplib (which is the http package in python3). |
|||
| msg211387 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年02月17日 02:32 | |
I suggest using setdefault() in urllib.request.AbstractHTTPHandler.do_open():
headers.setdefault("Connection", "close")
I am trying to work around a server that truncates its response when this header is sent, and this change would allow me to specify headers={"Connection", "Keep-Alive"} to get the same effect as dropping the Connection header. This is also consistent with the way the other headers (Accept-Encoding, User-Agent, Host) may be overridden.
|
|||
| msg221006 - (view) | Author: Demian Brecht (demian.brecht) * (Python triager) | Date: 2014年06月19日 16:33 | |
The problem here as far as I can tell is that the underlying file object (addinfourl) blocks while waiting for a full response from the server. As detailed in section 8.1 of RFC 2616, requests and responses can be pipelined, meaning requests can be sent while waiting for full responses from a server. The suggested change of overriding headers is only a partial solution as it doesn't allow for non-blocking pipelining. @Martin Panter: My suggestion for you would simply be to use http.client (httplib) as R. David Murray suggests, which doesn't auto-inject the Connection header. Also, a server truncating responses when "Connection: close" is sent sounds like a server-side bug to me. Unless you're a server maintainer (or have access to the developers), have you tried reaching out to them to request a fix? |
|||
| msg243879 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年05月23日 02:04 | |
So far the only reasons that have been given to override this header (mine and the one in Issue 15943) seem to be to work around buggy servers. It is already documented that HTTP 1.1 and "Connection: close" are used, so if this issue is only about working around buggy servers, the best thing might be to close this as being "not a Python bug". The user can always still use the low-level HTTP client, or make a custom urllib.request handler class (which is what I did). Shubhojeet: What was the reason you wanted to set a keep-alive header? If this is about proper keep-alive (a.k.a persistent) connection support in urllib.request, perhaps have a look at Issue 9740. |
|||
| msg250285 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2015年09月09日 05:07 | |
Just closed Issue 25037 about a server that omits the chunk length headers when "Connection: closed" is used. I wonder if it would be such a bad idea to just remove the "Connection: closed" flag. It was added in 2004 in revision 5e7455fb8db6, but I do not agree with the reason given in the commit message and comment. Adding the flag is only really a courtesy to the server, saying it can drop the connection once it sends the response. Removing it in theory shouldn’t change anything about how the client parses the HTTP response, but in practice it seems it may improve compatibility with buggy servers. |
|||
| msg363544 - (view) | Author: (henrik242) | Date: 2020年03月06日 20:33 | |
That mandatory "Connection: close" makes it impossible to POST a data request to Solr, as described in https://bugs.python.org/issue39875 It would be very helpful if it could be made optional. |
|||
| msg363697 - (view) | Author: (henrik242) | Date: 2020年03月09日 07:00 | |
Correction: My problem in Issue 39875 was not related to Connection: Close, but with weird POST handling in Solr. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:21 | admin | set | github: 57058 |
| 2020年03月09日 07:00:08 | henrik242 | set | messages: + msg363697 |
| 2020年03月06日 20:33:16 | henrik242 | set | nosy:
+ henrik242 messages: + msg363544 versions: + Python 3.7 |
| 2018年08月14日 05:42:56 | martin.panter | link | issue34357 superseder |
| 2015年09月09日 05:07:21 | martin.panter | set | status: pending -> open messages: + msg250285 |
| 2015年09月09日 04:30:37 | martin.panter | link | issue25037 superseder |
| 2015年05月23日 02:04:27 | martin.panter | set | status: open -> pending resolution: not a bug messages: + msg243879 |
| 2015年04月02日 03:07:33 | s7v7nislands@gmail.com | set | nosy:
+ s7v7nislands@gmail.com |
| 2015年02月13日 01:23:31 | demian.brecht | set | nosy:
- demian.brecht |
| 2014年06月19日 16:33:29 | demian.brecht | set | nosy:
+ demian.brecht messages: + msg221006 |
| 2014年02月17日 02:32:28 | martin.panter | set | messages: + msg211387 |
| 2014年02月17日 00:55:59 | martin.panter | set | nosy:
+ martin.panter |
| 2012年09月17日 23:27:58 | jcea | set | nosy:
+ jcea |
| 2012年09月14日 13:29:47 | r.david.murray | set | title: urllib2 headers issue -> Cannot override 'connection: close' in urllib2 headers |
| 2012年09月14日 13:28:57 | r.david.murray | set | nosy:
+ sanxiago, r.david.murray messages: + msg170476 versions: + Python 2.7, Python 3.2, Python 3.3, - Python 2.6 |
| 2012年09月14日 13:26:20 | r.david.murray | link | issue15943 superseder |
| 2011年08月28日 19:19:27 | shubhojeet.ghosh | create | |