Skip to content

Commit

Permalink
Support Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
welshjf committed Jun 17, 2015
1 parent 1a05193 commit 8a615bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion campbx/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from campbx import CampBX
from .campbx import CampBX
19 changes: 13 additions & 6 deletions campbx/campbx.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import urllib2
import base64
import simplejson as json
import logging
from urllib import urlencode
from functools import partial
try:
import urllib2
from urllib import urlencode
except ImportError:
import urllib.request as urllib2
from urllib.parse import urlencode

log = logging.getLogger(__name__)
log_formatter = logging.Formatter('%(name)s - %(message)s')
Expand All @@ -14,7 +18,10 @@
log.setLevel(logging.ERROR)

opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
opener.addheaders = [
('User-agent', 'Mozilla/5.0'),
('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8'),
]
urllib2.install_opener(opener)


Expand All @@ -24,7 +31,7 @@ def __new__(cls, func, conf, _repr):
return super(EndPointPartial, cls).__new__(cls, func, conf)

def __repr__(self):
return unicode('<API endpoint %s>' % self._repr)
return '<API endpoint %s>' % self._repr


class CampBX(object):
Expand Down Expand Up @@ -89,14 +96,14 @@ def _make_request(self, conf, post_params={}):
})

# url encode all parameters
data = urlencode(post_params)
data = urlencode(post_params).encode('utf-8')

# gimme some bitcoins!
try:
log.debug('Requesting data from %s' % url)
response = urllib2.urlopen(request, data)
return json.loads(response.read())
except urllib2.URLError, e:
except urllib2.URLError as e:
log.debug('Full error: %s' % e)
if hasattr(e, 'reason'):
self.log.error('Could not reach host. Reason: %s' % e.reason)
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries'
]
Expand Down

0 comments on commit 8a615bf

Please sign in to comment.