获取IP地理位置信息的最简单方法。
simple-geoip的Python项目详细描述
在python中获取ip地理位置信息的最简单的方法。
元
- 作者:Randall Degges
- 电子邮件:r@rdegges.com
- 推特:https://twitter.com/rdegges
- 网站:http://www.rdegges.com
- 状态:生产就绪
用法
一旦安装了简单的geoip,就可以使用它轻松地找到 给定IP地址的物理位置。
这个库允许您访问各种地理位置数据 您可以在应用程序中以多种方式使用。
fromsimple_geoipimportGeoIPgeoip=GeoIP("your-api-key");try:data=geoip.lookup("8.8.8.8")exceptConnectionError:# If you get here, it means you were unable to reach the geoipify# service, most likely because of a network error on your end.exceptServiceError:# If you get here, it means geoipify is having issues, so the request# couldn't be completed :(except:# Something else happened (non-geoipify) related. Maybe you hit CTRL-C# while the program was running, the kernel is killing your process, or# something else all together.print(data)
以下是执行geoip查找时可能返回的数据类型 请求:
{"ip":"8.8.8.8","location":{"country":"US","region":"California","city":"Mountain View","lat":37.40599,"lng":-122.078514,"postalCode":"94043","timezone":"-08:00"}}
默认情况下,此库为您处理重试失败的http请求。为了 实例:如果geoipify api服务当前已关闭或有问题, 您的请求将在失败前连续重试三次。
更改日志
所有库都按降序更改。
版本0.1.0
2018年4月26日发布。
- 第一次释放!