urllib2.urlopen will hang forever despite of timeout

后端 未结 3 964
醉梦人生
醉梦人生 2021-02-09 14:38

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

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-09 15:11

    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.

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

    Also, consider using requests:

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

    See also:

    • Proxies with Python 'Requests' module

提交回复
热议问题