« Return to Thread: [CPyUG:41451] 关于urllib2中的Keep-Alive及请教好用的http客户端包

[CPyUG:41455] Re: 关于urllib2中的Keep-Alive及请教好用的http客户端包

by hechu :: Rate this Message:

Reply to Author | View in Thread

这个问题去年有人讨论过,我也是搜索去年的邮件搜出来的相关信息。

我安装的是python2.5,在 urllib2.py 文件的第 1068 行。
也就是 AbstractHTTPHandler 这个类的 do_open 方法中。

注释说,addinfourl 类对持久链接没准备好。。。

代码片段如下:

# We want to make an HTTP/1.1 request, but the addinfourl
# class isn't prepared to deal with a persistent connection.
# It will try to read all remaining data from the socket,
# which will block while the server waits for the next request.
# So make sure the connection gets closed after the (only)
# request.
headers["Connection"] = "close"
headers = dict(
    (name.title(), val) for name, val in headers.items())
try:
    h.request(req.get_method(), req.get_selector(), req.data, headers)
    r = h.getresponse()
except socket.error, err: # XXX what error?
    raise URLError(err)



fluke.l 写道:
urllib2 中是什么地方的硬编码导致和keep-alive不兼容?

  

--~--~---------~--~----~------------~-------~--~----~
'''邮件来自Groups "python-cn"--China Py User Group
详情: http://groups-beta.google.com/group/python-cn
发言: python-cn@...
退订: python-cn-unsubscribe@...
维基: http://wiki.woodpecker.org.cn/moin/CPUG
珠江事务: http://groups.google.com/group/zpug
东南事务: http://groups.google.com/group/cpug-eastchina
北京事务: http://groups.google.com/group/bpug
中国事务: http://groups.google.com/group/CPUG
同质列表: http://python.cn/mailman/listinfo/python-chinese
'''
-~----------~----~----~----~------~----~------~--~---

 « Return to Thread: [CPyUG:41451] 关于urllib2中的Keep-Alive及请教好用的http客户端包