Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8 from mLewisLogic/master

Fix for "BitlyError: 'module' object has no attribute 'UrlError'"
  • Loading branch information...
commit 3b19d8ab89e0ba821c4b413676cd0c8d157a33fa 2 parents a1746bd + 7a2f88c
@jehiah jehiah authored
Showing with 10 additions and 10 deletions.
  1. +10 −10 bitly_api/bitly_http.py
View
20 bitly_api/bitly_http.py
@@ -9,10 +9,10 @@
"""
try:
import pycurl
- PYCURL=True
+ PYCURL = True
except ImportError:
- PYCURL=False
-
+ PYCURL = False
+
import urllib2
import cStringIO
@@ -25,22 +25,22 @@ def makeUrllib2Http(url, user_agent):
dont_redirect = DontRedirect()
opener = urllib2.build_opener(dont_redirect)
opener.addheaders = [('User-agent', user_agent + ' urllib')]
-
+
try:
response = opener.open(url)
code = response.code
data = response.read()
- except urllib2.UrlError, e:
+ except urllib2.URLError, e:
return 500, str(e)
except urllib2.HTTPError, e:
code = e.code
data = e.read()
return code, data
-
+
def makePycurlHttp(url, timeout, user_agent):
try:
buffer = cStringIO.StringIO()
-
+
curl = pycurl.Curl()
curl.setopt(pycurl.TIMEOUT_MS, timeout)
curl.setopt(pycurl.URL, url)
@@ -51,7 +51,7 @@ def makePycurlHttp(url, timeout, user_agent):
curl.setopt(pycurl.USERAGENT, user_agent + ' ' + pycurl.version)
# if referer:
# curl.setopt(pycurl.REFERER, referer)
-
+
curl.perform()
result = buffer.getvalue()
buffer.close()
@@ -64,10 +64,10 @@ def makePycurlHttp(url, timeout, user_agent):
pass
raise
return http_status_code, result
-
+
def get(url, timeout, user_agent):
if PYCURL:
code, result = makePycurlHttp(url, timeout, user_agent)
else:
code, result = makeUrllib2Http(url, user_agent)
- return {'http_status_code':code, 'result':result}
+ return {'http_status_code':code, 'result':result}
Please sign in to comment.
Something went wrong with that request. Please try again.