本文介绍了尽管超时,urllib2.urlopen将永远挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望这是一个非常简单的问题,但它让我发疯。
我在ubuntu 12.10服务器的开箱即用安装上使用Python 2.7.3。我一直在关注这个问题直到我得到这个片段:

Hope this is quite a simple question, but it's driving me crazy.I'm using Python 2.7.3 on an out of the box installation of ubuntu 12.10 server. I kept zooming on the problem until I got to this snippet:

import urllib2
x=urllib2.urlopen("http://casacinema.eu/movie-film-Matrix+trilogy+123+streaming-6165.html", timeout=5)

它只是永远挂起,永远不会超时。
我显然做错了什么。有人可以帮忙吗?
非常感谢你!

It simply hangs forever, never goes on timeout.I'm evidently doing something wrong. Anybody could please help?Thank you very much indeed!

Matteo

推荐答案

看起来您遇到了代理问题。以下是关于如何解决它的一个很好的解释:

Looks like you are experiencing the proxy issue. Here's a great explanation on how to workaround it:Trying to access the Internet using urllib2 in Python.

我已经使用python 2.7.3在我的ubuntu上执行了代码并且没有看到任何错误。

I've executed your code on my ubuntu with python 2.7.3 and haven't seen any errors.

另外,请考虑使用:

import requests

response = requests.get("http://casacinema.eu/movie-film-Matrix+trilogy+123+streaming-6165.html", timeout=5)
print response.status_code

参见:



  • Proxies with Python 'Requests' module

这篇关于尽管超时,urllib2.urlopen将永远挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 13:58