Geo Location extracted from visitors ip address

Νίκος Gr33k nikos at superhost.gr
Sat Jul 6 02:08:04 CEST 2013


Στις 6/7/2013 2:58 πμ, ο/η Νίκος Gr33k έγραψε:
> Στις 6/7/2013 2:55 πμ, ο/η Νίκος Gr33k έγραψε:
>> Στις 5/7/2013 10:58 μμ, ο/η Tim Chase έγραψε:
>>> On 2013-07-05 22:08, Νίκος Gr33k wrote:
>>>> Is there a way to extract out of some environmental variable the
>>>> Geo location of the user being the city the user visits out website
>>>> from?
>>>>
>>>> Perhaps by utilizing his originated ip address?
>>>
>>> Yep.  You can get an 11MB database (17MB uncompressed)
>>>
>>> http://dev.maxmind.com/geoip/legacy/downloadable/
>>
>>> http://pypi.python.org/pypi/pygeoip/         # pure Python
>>
>> Thank you very much Tim.
>> i am know trying to use it as:
>>
>> import pygeoip
>>
>> try:
>>    gic = pygeoip.GeoIP('/root/GeoIPCity.dat')
>>    host = gic.time_zone_by_addr( os.environ['HTTP_CF_CONNECTING_IP'] )
>> except Exception as e:
>>    host = repr(e)
>>
>> lets hope it will work!
>
> Just my luck again,
>
> PermissionError(13, 'Άρνηση πρόσβασης')
>
> Άρνηση πρόσβασης = Access Denied
>
> Why would that happen?

root at nikos [~]# ls -l GeoLiteCity.dat
-rw-r--r-- 1 root root 17633968 Jul  3 02:11 GeoLiteCity.dat
root at nikos [~]# chmod +x GeoLiteCity.dat
root at nikos [~]# ls -l GeoLiteCity.dat
-rwxr-xr-x 1 root root 17633968 Jul  3 02:11 GeoLiteCity.dat*
root at nikos [~]# python
Python 3.3.2 (default, Jun  3 2013, 16:18:05)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> import pygeoip
 >>> gic = pygeoip.GeoIP('/root/GeoIPCity.dat')
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File 
"/usr/local/lib/python3.3/site-packages/pygeoip-0.2.6-py3.3.egg/pygeoip/__init__.py", 
line 110, in __init__
     self._filehandle = codecs.open(filename, 'rb', ENCODING)
   File "/usr/local/lib/python3.3/codecs.py", line 884, in open
     file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: 
'/root/GeoIPCity.dat'
 >>>



-- 
What is now proved was at first only imagined!



More information about the Python-list mailing list