使用 Tor 作为代理时 Python urllib2 超时?
我使用 Python 的 urllib2 和 Tor 作为代理来访问网站。 当我 打开网站的主页,它工作正常,但是当我尝试查看登录页面时 (实际上并不是登录,而是只是查看)我收到以下错误...
URLError: <urlopen error (10060, 'Operation timed out')>
为了解决这个问题,我执行了以下操作:
import socket
socket.setdefaulttimeout(None).
我仍然收到相同的超时错误。
- 这是否意味着网站在服务器端超时? (我知道的不多 关于http进程,很抱歉,如果这是一个愚蠢的问题)
- 有什么方法可以纠正它,以便Python能够查看页面?
谢谢, 抢
I am using Python's urllib2 with Tor as a proxy to access a website. When I
open the site's main page it works fine but when I try to view the login page
(not actually log-in but just view it) I get the following error...
URLError: <urlopen error (10060, 'Operation timed out')>
To counteract this I did the following:
import socket
socket.setdefaulttimeout(None).
I still get the same timeout error.
- Does this mean the website is timing out on the server side? (I don't know much
about http processes so sorry if this is a dumb question) - Is there any way I can correct it so that Python is able to view the page?
Thanks,
Rob
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 Python Socket Documentation 默认值是没有超时,因此指定值“None” “是多余的。
您的连接断开的可能原因有多种。 一种可能是您的用户代理是“Python-urllib”,它很可能被阻止。 要更改您的用户代理:
您可能还想尝试覆盖代理设置,然后再尝试使用以下内容打开网址:
According to the Python Socket Documentation the default is no timeout so specifying a value of "None" is redundant.
There are a number of possible reasons that your connection is dropping. One could be that your user-agent is "Python-urllib" which may very well be blocked. To change your user agent:
You may also want to try overriding the proxy settings before you try and open the url using something along the lines of:
我对 Tor 的了解还不够确定,但超时可能不会发生在服务器端,而是发生在您和服务器之间的某个 Tor 节点上。 在这种情况下,除了重试连接之外,您无能为力。
I don't know enough about Tor to be sure, but the timeout may not happen on the server side, but on one of the Tor nodes somewhere between you and the server. In that case there is nothing you can do other than to retry the connection.
http://docs.python.org/library/urllib2.html
http://docs.python.org/library/urllib2.html