Giter Club home page Giter Club logo

Comments (7)

tiwilliam avatar tiwilliam commented on May 19, 2024

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.

tiwilliam avatar tiwilliam commented on May 19, 2024

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.

tiwilliam avatar tiwilliam commented on May 19, 2024

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.

vinitkumar avatar vinitkumar commented on May 19, 2024

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.

tiwilliam avatar tiwilliam commented on May 19, 2024

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.

vinitkumar avatar vinitkumar commented on May 19, 2024

@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.

tiwilliam avatar tiwilliam commented on May 19, 2024

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)

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.