Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 315
Daniel Crangu Avatar asked Dec 12 '13 14:12

Daniel Crangu


2 Answers

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)
#                                                           ^
like image 77
falsetru Avatar answered Oct 05 '22 13:10

falsetru


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

like image 22
Masoud Avatar answered Oct 05 '22 12:10

Masoud