Giter Site home page Giter Site logo

ipinfo / django Goto Github PK

View Code? Open in Web Editor NEW
55.0 55.0 19.0 79 KB

Official Django Library for IPinfo API (IP geolocation and other types of IP data)

Home Page: https://ipinfo.io

License: Apache License 2.0

Python 94.38% Shell 5.62%
django ip-address ip-database ip-geolocation ipinfo

django's People

Contributors

abdullahdevrel avatar coderholic avatar deltwalrus avatar elmigranto avatar jhtimmins avatar nareshkr22 avatar przmv avatar rm-umar avatar st-polina avatar umanshahzad avatar valentinogagliardi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django's Issues

Django runserver does not load when ipinfo middleware added in settings file

Hello, I am not sure if I am doing everything correctly but once I add the middleware definition for IPInfo in the settings.py file of my django project, I get the following error message.

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application
    return import_string(app_path)
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/kevin_tiba/PycharmProjects/animals/animals/wsgi.py", line 16, in <module>
    application = get_wsgi_application()
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 135, in __init__
    self.load_middleware()
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/core/handlers/base.py", line 35, in load_middleware
    middleware = import_string(middleware_path)
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/ipinfo_django/middleware.py", line 3, in <module>
    import ipinfo
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/ipinfo/__init__.py", line 1, in <module>
    from .handler import Handler
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/ipinfo/handler.py", line 10, in <module>
    from .cache.default import DefaultCache
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/ipinfo/cache/default.py", line 6, in <module>
    from .interface import CacheInterface
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/ipinfo/cache/interface.py", line 6, in <module>
    import six
ModuleNotFoundError: No module named 'six'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 137, in inner_run
    handler = self.get_handler(*args, **options)
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/Users/kevin_tiba/miniconda3/envs/django_env/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 50, in get_internal_wsgi_application
    ) from err
django.core.exceptions.ImproperlyConfigured: WSGI application 'animals.wsgi.application' could not be loaded; Error importing module.

Here is the middleware section:

MIDDLEWARE = [
    'ipinfo_django.middleware.IPinfo',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CSP Blocking requests

I'm using django 3.2.4 and ipinfo correctly parses requests done when testing on a local environment, but not in prod (deployed on google app engine). I assume it has to do with CSP blocking outgoing requests, but i added ipinfo.io to allowed request URLs, but it still defaults to showing every request as one made from the US (Mountain View). Any ideas?

Clarify current error behavior in docs and improve error handling

It's not clear in the docs what would happen if there's an error somewhere in the middleware, i.e. with a bad API key, getting rate limited, etc. We should link to https://docs.djangoproject.com/en/2.2/topics/http/middleware/#exception-handling at least to describe that Django would simply pass an HTTP response with status code 500 back up the middleware stack.

But that behavior is also not too desirable - getting rate limited shouldn't cause the site to respond with 429s or 500s. We should handle error cases gracefully within the middleware and putting that into the request object.

unresolved import 'ipinfo'

hie i am trying to import the ipinfo module in my django views but its giving me an error 'unresolved import 'ipinfo'..

image

django.core.exceptions.ImproperlyConfigured: WSGI application 'Mysite.wsgi.application' could not be loaded; Error importing module.

After update package ipinfo_django 1.2.0 to 1.3.0, It return me this error:

from ipinfo_django.ip_selector.default import DefaultIPSelector
ModuleNotFoundError: No module named 'ipinfo_django.ip_selector'
...
django.core.exceptions.ImproperlyConfigured: WSGI application 'Backend.wsgi.application' could not be loaded; Error importing module.

I already added 'ipinfo_django.middleware.IPinfo' in MIDDLEWARE

Add optional IP selection handler

Add an optional IP selection handler to the SDK client initialization step which accepts the request context and expects returning an IP.

The default handler, if no handler is specified by the user, will simply return the IP attached to the request object.

An additional handler should be available within the library, which looks into the X-Forwarded-For header and gets the first IP in the list if it exists, falling back to the IP attached to the request if the header isn't available. This is an implementation that users can optionally use instead of making their own.

asgiref version conflict with Django 4.0.7+

Reproduce:

  • Update Django to 4.0.7+
  • It requires asgiref<4 and asgiref>=3.4.1
  • however, asgiref past 3.2.1 makes django throw an ipinfo exception: 'IPinfo' object has no attribute '_is_coroutine'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.