Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
language: python
python:
- '2.6'
- '2.7'
- '3.3'
- '3.4'
Expand All @@ -27,7 +26,6 @@ before_install:
install:
- pip install -r requirements.txt
- pip install requests_mock pylint coveralls
- "if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then pip install unittest2 ipaddr; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install ipaddr; fi"
script:
- coverage run --source=geoip2 setup.py test
Expand Down
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
History
-------

2.8.0
+++++++++++++++++

* Python 2.6 support has been dropped. Python 2.7+ or 3.3+ is now required.
* Renamed user ID to account ID in the code and added support for the new
``ACCOUNT_ID_REQUIRED`` AND ``ACCOUNT_ID_UNKNOWN`` error codes.

2.7.0 (2018-01-18)
++++++++++++++++++

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Usage
-----

To use this API, you first create either a web service object with your
MaxMind ``user_id`` and ``license_key`` or a database reader object with the
MaxMind ``account_id`` and ``license_key`` or a database reader object with the
path to your database file. After doing this, you may call the method
corresponding to request type (e.g., ``city`` or ``country``), passing it the
IP address you want to look up.
Expand All @@ -65,7 +65,7 @@ Web Service Example
>>> import geoip2.webservice
>>>
>>> # This creates a Client object that can be reused across requests.
>>> # Replace "42" with your user ID and "license_key" with your license
>>> # Replace "42" with your account ID and "license_key" with your license
>>> # key.
>>> client = geoip2.webservice.Client(42, 'license_key')
>>>
Expand Down Expand Up @@ -385,7 +385,7 @@ correction, please `contact MaxMind support
Requirements
------------

This code requires Python 2.6+ or 3.3+. Older versions are not supported.
This code requires Python 2.7+ or 3.3+. Older versions are not supported.
This library has been tested with CPython and PyPy.

The Requests HTTP library is also required. See
Expand Down
26 changes: 10 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest',
'sphinx.ext.intersphinx', 'sphinx.ext.coverage']
extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx',
'sphinx.ext.coverage'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand Down Expand Up @@ -90,7 +92,6 @@
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []


# -- Options for HTML output ---------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
Expand Down Expand Up @@ -170,7 +171,6 @@
# Output file base name for HTML help builder.
htmlhelp_basename = 'geoip2doc'


# -- Options for LaTeX output --------------------------------------------

latex_elements = {
Expand All @@ -187,8 +187,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'geoip2.tex', 'geoip2 Documentation',
'Gregory Oschwald', 'manual'),
('index', 'geoip2.tex', 'geoip2 Documentation', 'Gregory Oschwald',
'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand All @@ -211,29 +211,24 @@
# If false, no module index is generated.
#latex_domain_indices = True


# -- Options for manual page output --------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'geoip2', 'geoip2 Documentation',
['Gregory Oschwald'], 1)
]
man_pages = [('index', 'geoip2', 'geoip2 Documentation', ['Gregory Oschwald'],
1)]

# If true, show URL addresses after external links.
#man_show_urls = False


# -- Options for Texinfo output ------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'geoip2', 'geoip2 Documentation',
'Gregory Oschwald', 'geoip2', 'One line description of project.',
'Miscellaneous'),
('index', 'geoip2', 'geoip2 Documentation', 'Gregory Oschwald', 'geoip2',
'One line description of project.', 'Miscellaneous'),
]

# Documents to append as an appendix to all manuals.
Expand All @@ -245,6 +240,5 @@
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'http://docs.python.org/': None}
37 changes: 26 additions & 11 deletions geoip2/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class Client(object):

It accepts the following required arguments:

:param user_id: Your MaxMind User ID.
:param account_id: Your MaxMind account ID.
:param license_key: Your MaxMind license key.

Go to https://www.maxmind.com/en/my_license_key to see your MaxMind
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the next line we say "User ID". Should we update that too?

User ID and license key.
account ID and license key.

The following keyword arguments are also accepted:

Expand Down Expand Up @@ -82,20 +82,34 @@ class Client(object):

"""

def __init__(self,
user_id,
license_key,
host='geoip.maxmind.com',
locales=None,
timeout=None):
def __init__(
self,
account_id=None,
license_key=None,
host='geoip.maxmind.com',
locales=None,
timeout=None,

# This is deprecated and not documented for that reason.
# It can be removed if we do a major release in the future.
user_id=None):
"""Construct a Client."""
# pylint: disable=too-many-arguments
if locales is None:
locales = ['en']
if account_id is None:
account_id = user_id

if account_id is None:
raise TypeError('The account_id is a required parameter')
if license_key is None:
raise TypeError('The license_key is a required parameter')

self._locales = locales
# requests 2.12.2 requires that the username passed to auth be bytes
# or a string, with the former being preferred.
self._user_id = user_id if isinstance(user_id, bytes) else str(user_id)
self._account_id = account_id if isinstance(account_id,
bytes) else str(account_id)
self._license_key = license_key
self._base_uri = 'https://%s/geoip/v2.1' % host
self._timeout = timeout
Expand Down Expand Up @@ -143,7 +157,7 @@ def _response_for(self, path, model_class, ip_address):
uri = '/'.join([self._base_uri, path, ip_address])
response = requests.get(
uri,
auth=(self._user_id, self._license_key),
auth=(self._account_id, self._license_key),
headers={
'Accept': 'application/json',
'User-Agent': self._user_agent()
Expand Down Expand Up @@ -201,7 +215,8 @@ def _exception_for_4xx_status(self, response, status, uri):
def _exception_for_web_service_error(self, message, code, status, uri):
if code in ('IP_ADDRESS_NOT_FOUND', 'IP_ADDRESS_RESERVED'):
return AddressNotFoundError(message)
elif code in ('AUTHORIZATION_INVALID', 'LICENSE_KEY_REQUIRED',
elif code in ('ACCOUNT_ID_REQUIRED', 'ACCOUNT_ID_UNKNOWN',
'AUTHORIZATION_INVALID', 'LICENSE_KEY_REQUIRED',
'USER_ID_REQUIRED', 'USER_ID_UNKNOWN'):
return AuthenticationError(message)
elif code in ('INSUFFICIENT_FUNDS', 'OUT_OF_QUERIES'):
Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
package_data={'': ['LICENSE']},
package_dir={'geoip2': 'geoip2'},
include_package_data=True,
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*',
install_requires=requirements,
extras_require={
':python_version=="2.6" or python_version=="2.7"': ['ipaddress']
},
extras_require={':python_version=="2.7"': ['ipaddress']},
tests_require=['requests_mock>=0.5'],
test_suite="tests",
license=geoip2.__license__,
Expand All @@ -37,7 +36,6 @@
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
Expand All @@ -47,4 +45,5 @@
'Programming Language :: Python',
'Topic :: Internet :: Proxy Servers',
'Topic :: Internet',
], )
],
)
Loading