扫描urllib2
源后,即使您指定保持活动状态,连接似乎也会自动关闭。
为什么是这样?
因为现在我只是httplib
用于我的持久连接......但想知道为什么这在 urllib2 中被禁用(或者可能只是模棱两可)。
扫描urllib2
源后,即使您指定保持活动状态,连接似乎也会自动关闭。
为什么是这样?
因为现在我只是httplib
用于我的持久连接......但想知道为什么这在 urllib2 中被禁用(或者可能只是模棱两可)。
这是 urllib2(和 urllib 也是如此)的众所周知的限制。恕我直言,迄今为止修复它并使其正确的最佳尝试是 Garry Bodsworth 的用于 Python 2.6 或 2.7 的coda_network —— urllib2(和其他一些模块)的替换、修补版本以支持保持活动(以及一堆其他更小但相当欢迎修复)。
You might also check out httplib2, which supports persistent connections. Not quite the same as urllib2 (in the sense that it only does http and not "any kind of url"), but easier than httplib (and imho also easier than urllib2 if you really want to do http).