mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-17 11:49:29 +00:00
Added timeout options for Python 2.6 and above
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import sys
|
||||||
import urllib, urllib2
|
import urllib, urllib2
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
@@ -65,7 +66,10 @@ class CachedDocumentManager(models.Manager):
|
|||||||
req = urllib2.Request(url)
|
req = urllib2.Request(url)
|
||||||
req.add_header('CCP-Contact', 'matalok@pleaseignore.com')
|
req.add_header('CCP-Contact', 'matalok@pleaseignore.com')
|
||||||
try:
|
try:
|
||||||
|
if sys.version_info < (2, 6):
|
||||||
conn = urllib2.urlopen(req)
|
conn = urllib2.urlopen(req)
|
||||||
|
else:
|
||||||
|
conn = urllib2.urlopen(req, timeout=5)
|
||||||
except urllib2.HTTPError, e:
|
except urllib2.HTTPError, e:
|
||||||
print "HTTP Error Code: %s" % e.code
|
print "HTTP Error Code: %s" % e.code
|
||||||
raise DocumentRetrievalError(e.code)
|
raise DocumentRetrievalError(e.code)
|
||||||
|
|||||||
Reference in New Issue
Block a user