Search code examples
pythonsocketspython-2.7error-handlingtimeout

._GLOBAL_DEFAULT_TIMEOUT occurs on simple urlopen


I've got a problem which is this:

Sorry
Traceback (most recent call last):
File "testconn.py", line 2, in <module>
import httplib
File "C:\Python27\lib\httplib.py", line 680, in <module>
class HTTPConnection:
File "C:\Python27\lib\httplib.py", line 692, in HTTPConnection
timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None):
AttributeError: 'module' object has no attribute '_GLOBAL_DEFAULT_TIMEOUT'   

I seriously didn't have this issue like 3 days ago, everything was working fine and now this. Here's my code: (To mention that I tried adding timeout, I tried following the strict syntax of urlopen (Adding timeout aswell). Nothing seemed to do it.)

import httplib
import urllib2

headers = {"pragma" : "no-cache"}
req = urllib2.Request("http://google.com/", headers = header)
response=urllib2.urlopen(req)

print response

I'd appreciate any help.


Solution

  • Check if you have your own socket.py file. That shadows import of standard library socket module.

    Find it, rename(or remove) it. You should also rename(or remove) socket.pyc.


    BTW, the following line has a typo ( header s )

    req = urllib2.Request("http://google.com/", headers = header)
    #                                                           ^