python套接字问题

发布于 2024-08-31 17:42:55 字数 392 浏览 1 评论 0原文

我写了这个Python代码:

import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "64.83.219.7", 58279)
socket.socket = socks.socksocket
socket.setdefaulttimeout(19)
import urllib2
print urllib2.urlopen('http://www.google.com').read()

但是当我执行它时,我得到这个错误:

urllib2.URLError: <urlopen error timed out>

我做错了什么?

I write this python code:

import socks
import socket
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "64.83.219.7", 58279)
socket.socket = socks.socksocket
socket.setdefaulttimeout(19)
import urllib2
print urllib2.urlopen('http://www.google.com').read()

but when I execute it, I get this error:

urllib2.URLError: <urlopen error timed out>

What am I doing wrong?

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

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

发布评论

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

评论(1

不离久伴 2024-09-07 17:42:55

您的脚本中出现超时。我猜想由于代理设置错误而连接到谷歌。我认为您的目标是通过代理获取 http://www.google.com 的内容?
我不知道使用套接字/袜子模块设置它的方法。也许您想查看 python 文档中的以下章节:

http://docs.python.org/library/urllib2.html?highlight=urllib2#examples(代码sinppet 5和上面的文本)

http://docs.python.org/library/urllib2.html?highlight=urllib2#urllib2.Request.set_proxy

http://docs.python.org/library/urllib2 .html?highlight=urllib2#pr​​oxyhandler-objects

Something timed out in your script. I guess the connection to google because of wrong proxy setup. I think your goal is to fetch the contents of http://www.google.com through a proxy?
I don't know about this method to set it using socket/socks module. Maybe you want to take a look at the following chapters in the python documentation:

http://docs.python.org/library/urllib2.html?highlight=urllib2#examples (code sinppet 5 and the text above)

http://docs.python.org/library/urllib2.html?highlight=urllib2#urllib2.Request.set_proxy

http://docs.python.org/library/urllib2.html?highlight=urllib2#proxyhandler-objects

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文