Ubuntu 10.10 上奇怪的 urllib2.urlopen() 行为

发布于 2024-09-30 12:54:35 字数 153 浏览 0 评论 0原文

我在 Ubuntu 10.10 上遇到 urllib2.urlopen() 的奇怪行为。对 URL 的第一个请求速度很快,但第二个请求需要很长时间才能连接。我认为5到10秒之间。在 Windows 上这工作正常吗?

有人知道什么可能导致这个问题吗?

谢谢,小野

I am experiencing strange behavior with urllib2.urlopen() on Ubuntu 10.10. The first request to a url goes fast but the second takes a long time to connect. I think between 5 and 10 seconds. On windows this just works normal?

Does anybody have an idea what could cause this issue?

Thanks, Onno

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失而复得 2024-10-07 12:54:35

5 秒听起来很像 DNS 解析超时。

预感,它可能会循环访问 /etc/resolv.conf 中的 DNS 服务器,如果其中一个服务器损坏,Linux 上的默认超时为 5 秒,之后它将尝试下一个,当它尝试完所有这些后循环回到顶部。

如果 resolv.conf 中列出了多个 DNS 服务器,请尝试删除除一个之外的所有服务器。如果这解决了问题;然后看看为什么你被分配了不正确的解析服务器。

5 seconds sounds suspiciously like the DNS resolving timeout.

A hunch, It's possible that it's cycling through the DNS servers in your /etc/resolv.conf and if one of them is broken, the default timeout is 5 seconds on linux, after which it will try the next one, looping back to the top when it's tried them all.

If you have multiple DNS servers listed in resolv.conf, try removing all but one. If this fixes it; then after that see why you're being assigned incorrect resolving servers.

深海蓝天 2024-10-07 12:54:35

您可以启用 urllib2 的调试也许它可以帮助您找出问题

import urllib2

opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))
opener.open('http://www.google.com')

you can enable debugging of the urllib2 maybe it can help you found out the problem

import urllib2

opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=1))
opener.open('http://www.google.com')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文