gpt4 book ai didi

python - 尽管超时,urllib2.urlopen 将永远挂起

转载 作者:太空狗 更新时间:2023-10-30 01:09:05 24 4
gpt4 key购买 nike

希望这是一个非常简单的问题,但它让我发疯。我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com