Skip to content

Commit 62a9394

Browse files
authored
Merge pull request maxmind#39 from maxmind/greg/fix-basic-auth
Fix basic auth issue with requests 2.12.2 and 2.12.3
2 parents 19c1ab6 + 5626376 commit 62a9394

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ python:
66
- '3.3'
77
- '3.4'
88
- '3.5'
9+
- '3.6-dev'
910
- nightly
1011
- pypy
1112
matrix:

HISTORY.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
History
44
-------
55

6+
2.4.2 (2016-12-08)
7+
++++++++++++++++++
8+
9+
* Recent releases of ``requests`` (2.12.2 and 2.12.3) require that the
10+
username for basic authentication be a string or bytes. The documentation
11+
for this module uses an integer for the ``user_id``, which will break with
12+
these ``requests`` versions. The ``user_id`` is now converted to bytes
13+
before being passed to ``requests``.
14+
615
2.4.1 (2016-11-21)
716
++++++++++++++++++
817

geoip2/webservice.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ def __init__(self,
9393
if locales is None:
9494
locales = ['en']
9595
self._locales = locales
96-
self._user_id = user_id
96+
# requests 2.12.2 requires that the username passed to auth be bytes
97+
# or a string, with the former being preferred.
98+
self._user_id = str(user_id).encode()
9799
self._license_key = license_key
98100
self._base_uri = 'https://%s/geoip/v2.1' % host
99101
self._timeout = timeout
@@ -141,8 +143,10 @@ def _response_for(self, path, model_class, ip_address):
141143
uri = '/'.join([self._base_uri, path, ip_address])
142144
response = requests.get(uri,
143145
auth=(self._user_id, self._license_key),
144-
headers={'Accept': 'application/json',
145-
'User-Agent': self._user_agent()},
146+
headers={
147+
'Accept': 'application/json',
148+
'User-Agent': self._user_agent()
149+
},
146150
timeout=self._timeout)
147151
if response.status_code == 200:
148152
body = self._handle_success(response, uri)

0 commit comments

Comments
 (0)