Daniel Crangu
Daniel Crangu

Reputation: 107

._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.

Upvotes: 5

Views: 7098

Answers (2)

Masoud
Masoud

Reputation: 1064

Also if you're importing Flask in socket.py file, you should change file name to something else.

Upvotes: 2

falsetru
falsetru

Reputation: 369424

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)
#                                                           ^

Upvotes: 21

Related Questions