Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket has no inet_pton method in Python 2.7 on Windows #4

Closed
EmilStenstrom opened this issue Apr 25, 2014 · 5 comments
Closed

Socket has no inet_pton method in Python 2.7 on Windows #4

EmilStenstrom opened this issue Apr 25, 2014 · 5 comments

Comments

@EmilStenstrom
Copy link

Hi,

This library does not work with Python 2.7 on Windows at the moment since the socket module does not have a inet_pton there. Is windows support on your radar?

Stacktrace when running a simple lookup.ip():

Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Admin\Envs\presskoll\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "C:\Users\Admin\Envs\presskoll\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Admin\Envs\presskoll\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Users\Admin\Envs\presskoll\lib\site-packages\django\core\management\base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "C:\Emils\Projects\presskoll\presskoll\webhook\management\commands\extract_sources.py", line 24, in handle
    match = geolite2.lookup(ip)
  File "C:\Users\Admin\Envs\presskoll\lib\site-packages\geoip.py", line 364, in lookup
    return self._get_actual_db().lookup(ip_addr)
  File "C:\Users\Admin\Envs\presskoll\lib\site-packages\geoip.py", line 204, in lookup
    return self._lookup(ip_addr)
  File "C:\Users\Admin\Envs\presskoll\lib\site-packages\geoip.py", line 249, in _lookup
    packed_addr = pack_ip(ip_addr)
  File "C:\Users\Admin\Envs\presskoll\lib\site-packages\geoip.py", line 34, in pack_ip
    return socket.inet_pton(fmly, ip)
AttributeError: 'module' object has no attribute 'inet_pton'
@EmilStenstrom
Copy link
Author

Luckily, it seems to be easily monkey-patched: Just import [https://gist.github.com/nnemkin/4966028](this windows implementation) and monkey-patch socket.inet_pton and things work fine.

@hickeroar
Copy link

FYI, I've packaged up a solution to this problem based on that above gist: https://pypi.python.org/pypi/win_inet_pton

@EmilStenstrom
Copy link
Author

Thank you!

@anviloro
Copy link

anviloro commented Nov 5, 2015

Thank you!!!, just my 2 cents for newbies like me, after downloading the package, you need to import win_inet_pton in \Lib\site-packages\geoip.py and works like a charm.

@6233114
Copy link

6233114 commented Sep 22, 2016

This is what worked for a newbie (like me):

  1. Install win inet pton using terminal or cmd
  2. Run pip install win-inet-pton
  3. In the project code add import win_inet_pton in \Lib\site-packages\geoip.py as @anviloro suggests (above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants