Comments (7)
As I see socket.AF_INET6
in your trace I assume you pass a IPv6 address, can you tell me which address your are trying to look up?
from pygeoip.
Note: This error is raised since the underlying inet_pton
implementation raise a validation error. See this man page for details in-case you use Linux: http://man7.org/linux/man-pages/man3/inet_pton.3.html
from pygeoip.
Could this be a case of whitespace around your input address?
>>> socket.inet_pton(socket.AF_INET, '127.0.0.1 ')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.error: illegal IP address string passed to inet_pton
from pygeoip.
Here:
[28/10/14 4:58:28 pm] Aashish Sangle: 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36',
'HTTP_VIA': '1.1 gatewaymtl (squid), 1.1 vegur',
'HTTP_X_FORWARDED_FOR': 'unknown, 185.15.249.252',
[28/10/14 4:58:34 pm] Aashish Sangle: 'REMOTE_ADDR': '10.62.253.228',
'REMOTE_PORT': '14782',
ip : 'unknown' stack trace from app
So the code doesn't check if it's a valid ip using some regex? You think it is a good idea to make sure the ip passing after confirming it is a valid ip address?
Update:
Found out that squid proxy alters the ip address and appends Unknown to it making the pygeoip and underlying code crash because of an invalid ip address.
from pygeoip.
I would argue that passing unknown, 185.15.249.252
to the lookup and then get socket.error: illegal IP address string passed to inet_pton
back is pretty reasonable and expected. Not sure what we will gain from a catch and raise.
from pygeoip.
@tiwilliam Actually, I am not passing this IP address as one of our client is accessing the service from behind a firewall. My suggestion is that pygeoip assumes that the IP passed to it is a valid IP address which might not be true when the request comes behind a firewall which modifies the IP address making it an illegal IP address.
The whole point of using a geoip based backend is to provide redirection/timezone awareness (our use case) to the system. If it crashes for requests behinds the firewall, it beats the purpose of using it in first place. I hope you understand my problem. Also, I don't think there is much code involved in getting this fix and it is not going to affect the code in any negative way. Validating an IP address is not a bad thing AFAIK. Please let me know if I misunderstood anything.
from pygeoip.
I get your point, but in this case I think the error is how your application is parsing the X-Forwarded-For
header. X-Forwarded-For
may contain a list of hosts, it can for example look like this: 127.0.0.1, 10.62.253.228, 185.15.249.252
. I don't think pygeoip
is responsible for guessing which one of these you want to lookup. X-Forwarded-For
may also contain port numbers, so I will leave this to a proper HTTP library to parse.
from pygeoip.
Related Issues (20)
- Package documentation is formatted as text on PyPI HOT 6
- Add support for MaxMind DB (.mmdb) files HOT 2
- ValueError: seek out of range HOT 2
- Works with Python 3.4 HOT 1
- ImportError: No module named 'pygeoip' HOT 7
- GeoLite2 City DB returns pygeoip.GeoIPError: Invalid database type, expected City HOT 1
- Correctly using pygeoip inside a Django app HOT 4
- Exception handler cannot make up its mind. HOT 13
- Mo netspeeds, mo problems HOT 1
- Inconsistent / missing results from Region database HOT 6
- Release 0.3.2 HOT 1
- "pygeoip __init__.py _gethostbyname" Error. HOT 1
- pygeoip don't support region_name? HOT 1
- I cant load MindMax database HOT 1
- IPV6 results returned on database not supporting IPV6
- region_name not available HOT 1
- timezones are not IANA standard
- MaxMind GeoIP now has an officiel Python lib
- rare `string index out of range` issue,
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pygeoip.