希望这是一个非常简单的问题,但它让我发疯。 我在 ubuntu 12.10 服务器的开箱即用安装中使用 Python 2.7.3。我一直在关注这个问题,直到我看到这个片段:
import urllib2
x=urllib2.urlopen("http://casacinema.eu/movie-film-Matrix+trilogy+123+streaming-6165.html", timeout=5)
它只是永远挂起,永远不会超时。 我显然做错了什么。有人可以帮忙吗? 真的非常感谢!
马特奥
最佳答案
您似乎遇到了代理问题。这是关于如何解决它的一个很好的解释: Trying to access the Internet using urllib2 in Python .
我已经在我的 ubuntu 上用 python 2.7.3 执行了你的代码,没有发现任何错误。
另外,考虑使用 requests :
import requests
response = requests.get("http://casacinema.eu/movie-film-Matrix+trilogy+123+streaming-6165.html", timeout=5)
print response.status_code
另见:
关于python - 尽管超时,urllib2.urlopen 将永远挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16772795/