๐ฌ Ask me about FreeSoftware and Python !
rednaks / django-ip-geolocation Goto Github PK
View Code? Open in Web Editor NEWIP Geolocation Hooks for django
Home Page: https://pypi.org/project/django-ip-geolocation/
License: MIT License
IP Geolocation Hooks for django
Home Page: https://pypi.org/project/django-ip-geolocation/
License: MIT License
It would be nice to have support for ipgeolocation.io
add force ip to the settings, it's very useful in dev mode
http://doapi.us/ip/ { IP }/json
This is free api, unlimited request, hope you add this
use travis or githubworkflows to test and publish on pypi
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'
Requirements:
cookies size can impact the webapp perfs, and must be minimized as possible.
thus the raw_data
should be removed from cookies.
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'
Would you be considered to add another geolocation service - IP2Location web service into this project? If yes, you can sign up for a trial account at https://www.ip2location.com/web-service/ip2location for development. If you need any assistance, please let us know.
@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.
The view django_ip_geolocation.decorators.inner didn't return an HttpResponse object.
It returned None instead.
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
the _parse()
method should be called before requesting data, not after geolocation.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.