Giter Site home page Giter Site logo

rednaks / django-ip-geolocation Goto Github PK

View Code? Open in Web Editor NEW
36.0 36.0 6.0 90 KB

IP Geolocation Hooks for django

Home Page: https://pypi.org/project/django-ip-geolocation/

License: MIT License

Python 98.13% Makefile 1.87%
django hacktoberfest hooks middleware plugin python

django-ip-geolocation's Introduction

Hi there ๐Ÿ‘‹

๐Ÿ’ฌ Ask me about FreeSoftware and Python !

GitHub Stats:



GitHub Trophies:


django-ip-geolocation's People

Contributors

girishkumarkh avatar rednaks 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

Watchers

 avatar  avatar  avatar  avatar

django-ip-geolocation's Issues

CI/CD

use travis or githubworkflows to test and publish on pypi

protect raw data from being None

This happens on some occasions when geolocate IP couldn't find the IP's location

Error log:

backend_1      |  [2021-03-24 11:20:45,391] root         ERROR    Couldn't geolocate ip (middleware 1 140405557767496)
backend_1      | Traceback (most recent call last):
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/middleware.py", line 26, in process_request
backend_1      |     self._get_geolocation(request)
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/middleware.py", line 61, in _get_geolocation
backend_1      |     self._geolocation_data = get_geolocation(request)
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/utils.py", line 52, in get_geolocation
backend_1      |     return backend_instance.data()
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/backends/base.py", line 33, in data
backend_1      |     self._parse()
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/backends/ipdataco.py", line 26, in _parse
backend_1      |     self._continent = self._raw_data.get('continent_name')
backend_1      | AttributeError: 'NoneType' object has no attribute 'get'
backend_1      | [2021-03-24 11:20:45,533] root         ERROR    Couldn't geolocate ip (middleware 1 140405557767496)
backend_1      | Traceback (most recent call last):
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/middleware.py", line 42, in process_response
backend_1      |     self._get_geolocation(request)
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/middleware.py", line 61, in _get_geolocation
backend_1      |     self._geolocation_data = get_geolocation(request)
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/utils.py", line 52, in get_geolocation
backend_1      |     return backend_instance.data()
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/backends/base.py", line 33, in data
backend_1      |     self._parse()
backend_1      |   File "/usr/local/lib/python3.8/site-packages/django_ip_geolocation/backends/ipdataco.py", line 26, in _parse
backend_1      |     self._continent = self._raw_data.get('continent_name')
backend_1      | AttributeError: 'NoneType' object has no attribute 'get'

cookies not working in python 3.x

  File "django-ip-geolocation/django_ip_geolocation/middleware.py", line 46, in process_response
    set_cookie(response, cleaned_geolocation_data)
  File "django-ip-geolocation/django_ip_geolocation/utils.py", line 68, in set_cookie
    encoded_data = base64.b64encode(json.dumps(geolocation_data))
  File "/usr/lib/python3.7/base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'str'

Idea of retrieving geolocation data from cookie if present

@rednaks have you thought about retrieving the geolocation from the cookie so that we don't need to call the API every single request?

Use case: a typical user will visit multiple pages per site and it's very unlikely their geolocation will change on every request. But calling the API on every single request can be changed to only when the cookie doesn't exist.

returns None

The view django_ip_geolocation.decorators.inner didn't return an HttpResponse object.
It returned None instead.

Middleware fails

Using the middleware in settings.py throws error:

File "C:\Program Files\Python37\lib\site-packages\django_ip_geolocation\middleware.py", line 15, in __init__
  super(IpGeolocationMiddleware).__init__(get_response)
TypeError: super() argument 1 must be type, not function

refactor interface

the _parse() method should be called before requesting data, not after geolocation.

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.