问题

在使用geoip2模块去解析ip地址是出现了错误:InvalidDatabaseError: Invalid node in search tree

(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz ~]$ ipython
Python 3.6.8 (default, Jan 17 2019, 16:30:37)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.In [1]: import geoip2.databaseIn [2]: reader = geoip2.database.Reader('GeoLite2-City.mmdb')In [3]: reader.city("117.136.81.221")
---------------------------------------------------------------------------
InvalidDatabaseError                      Traceback (most recent call last)
<ipython-input-3-d3607d6e2613> in <module>
----> 1 reader.city("117.136.81.221")/data/hilqiqi0/venv/lib/python3.6/site-packages/geoip2/database.py in city(self, ip_address)112113         """
--> 114         return self._model_for(geoip2.models.City, 'City', ip_address)115116     def anonymous_ip(self, ip_address):/data/hilqiqi0/venv/lib/python3.6/site-packages/geoip2/database.py in _model_for(self, model_class, types, ip_address)193194     def _model_for(self, model_class, types, ip_address):
--> 195         record = self._get(types, ip_address)196         record.setdefault('traits', {})['ip_address'] = ip_address197         return model_class(record, locales=self._locales)/data/hilqiqi0/venv/lib/python3.6/site-packages/geoip2/database.py in _get(self, database_type, ip_address)186                             "%s database" % (caller,187                                              self.metadata().database_type))
--> 188         record = self._db_reader.get(ip_address)189         if record is None:190             raise geoip2.errors.AddressNotFoundError(/data/hilqiqi0/venv/lib/python3.6/site-packages/maxminddb/reader.py in get(self, ip_address)114                 'Error looking up {0}. You attempted to look up '115                 'an IPv6 address in an IPv4-only database.'.format(ip_address))
--> 116         pointer = self._find_address_in_tree(address)117118         return self._resolve_data_pointer(pointer) if pointer else None/data/hilqiqi0/venv/lib/python3.6/site-packages/maxminddb/reader.py in _find_address_in_tree(self, ip_address)135             return node136
--> 137         raise InvalidDatabaseError('Invalid node in search tree')138139     def _start_node(self, length):InvalidDatabaseError: Invalid node in search treeIn [4]: quit()

问题分析

由于之前使用的程序没有问题,在本机电脑上运行也正常,换了台服务器就蹦了;从最开始找代码问题,到怀疑模块版本和python版本不匹配,然后到怀疑python基础代码有问题,最后重新下载文件、重新解压才正常。
必须用gunzip进行解压(https://github.com/maxmind/MaxMind-DB-Reader-python );文件地址(https://dev.maxmind.com/geoip/geoip2/geolite2/ )


(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz geoip]$ wget https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
--2019-05-14 10:33:41--  https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
Resolving geolite.maxmind.com (geolite.maxmind.com)... 104.17.201.89, 104.17.200.89, 2606:4700::6811:c959, ...
Connecting to geolite.maxmind.com (geolite.maxmind.com)|104.17.201.89|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 29204309 (28M) [application/gzip]
Saving to: ‘GeoLite2-City.tar.gz’100%[=======================================================================================>] 29,204,309  8.90MB/s   in 3.1s2019-05-14 10:33:45 (8.90 MB/s) - ‘GeoLite2-City.tar.gz’ saved [29204309/29204309](venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz geoip]$ ls
GeoLite2-City.tar.gz
(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz geoip]$ gunzip GeoLite2-City.tar.gz
(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz geoip]$ ls
GeoLite2-City.tar
(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz geoip]$ tar -xvf GeoLite2-City.tar
GeoLite2-City_20190514/
GeoLite2-City_20190514/COPYRIGHT.txt
GeoLite2-City_20190514/README.txt
GeoLite2-City_20190514/LICENSE.txt
GeoLite2-City_20190514/GeoLite2-City.mmdb
(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz geoip]$ ls
GeoLite2-City_20190514  GeoLite2-City.tar
(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz geoip]$ cd GeoLite2-City_20190514/
(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz GeoLite2-City_20190514]$ ls
COPYRIGHT.txt  GeoLite2-City.mmdb  LICENSE.txt  README.txt
(venv) [hilqiqi0@izbp1a3rsiacm6nu3bfnyuz GeoLite2-City_20190514]$ ipython
Python 3.6.8 (default, Jan 17 2019, 16:30:37)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.5.0 -- An enhanced Interactive Python. Type '?' for help.In [1]: import geoip2.databaseIn [2]: reader = geoip2.database.Reader('GeoLite2-City.mmdb')In [3]: reader.city("117.136.81.221")
Out[3]: geoip2.models.City({'city': {'geoname_id': 1791247, 'names': {'de': 'Wuhan', 'en': 'Wuhan', 'es': 'Wuhan', 'fr': 'Wuhan', 'ja': '武漢市', 'pt-BR': 'Wuhan', 'ru': 'Ухань', 'zh-CN': '武汉'}}, 'continent': {'code': 'AS', 'geoname_id': 6255147, 'names': {'de': 'Asien', 'en': 'Asia', 'es': 'Asia', 'fr': 'Asie', 'ja': 'アジア', 'pt-BR': 'Ásia', 'ru': 'Азия', 'zh-CN': '亚洲'}}, 'country': {'geoname_id': 1814991, 'iso_code': 'CN', 'names': {'de': 'China', 'en': 'China', 'es': 'China', 'fr': 'Chine', 'ja': '中国', 'pt-BR': 'China', 'ru': 'Китай', 'zh-CN': '中国'}}, 'location': {'accuracy_radius': 200, 'latitude': 30.5856, 'longitude': 114.2665, 'time_zone': 'Asia/Shanghai'}, 'registered_country': {'geoname_id': 1814991, 'iso_code': 'CN', 'names': {'de': 'China', 'en': 'China', 'es': 'China', 'fr': 'Chine', 'ja': '中国', 'pt-BR': 'China', 'ru': 'Китай', 'zh-CN': '中国'}}, 'subdivisions': [{'geoname_id': 1806949, 'iso_code': 'HB', 'names': {'de': 'Hubei', 'en': 'Hubei', 'es': 'Hubei', 'fr': 'Province de Hubei', 'ja': '湖北省', 'pt-BR': 'Hubei', 'ru': 'Хубэй', 'zh-CN': '湖北省'}}], 'traits': {'ip_address': '117.136.81.221'}}, ['en'])In [4]:

geoip2 InvalidDatabaseError: Invalid node in search tree相关推荐

  1. 笔试算法题(58):二分查找树性能分析(Binary Search Tree Performance Analysis)

    议题:二分查找树性能分析(Binary Search Tree Performance Analysis) 分析: 二叉搜索树(Binary Search Tree,BST)是一颗典型的二叉树,同时任 ...

  2. 【ACM】二叉搜索树(Binary Search Tree /BS Tree) 小结

    动态管理集合的数据结构--二叉搜索树 搜索树是一种可以进行插入,搜索,删除等操作的数据结构,可以用字典或者优先队列. 二叉排序树又称为二叉查找树,他或者为空树,或者是满足如下性质的二叉树. (1)若它 ...

  3. 二叉搜索树(binary search tree)的建立、删除、查找

    由于输入的数据顺序不同,建立的bst会不一样.最坏的情况就是一个链,所以我们引入了平衡二叉树的概念.这里我们先来看binary search tree.(我随笔里面有一些相关知识) 建立(也就是插入) ...

  4. 查找二叉树中出现次数最多的数 Find Mode in Binary Search Tree

    为什么80%的码农都做不了架构师?>>>    问题: Given a binary search tree (BST) with duplicates, find all the  ...

  5. LeetCode 426. Convert Binary Search Tree to Sorted Doubly Linked List--转换二叉树为双向链表--Java,C++,Python解法

    题目地址:Convert Binary Search Tree to Sorted Doubly Linked List - LeetCode Convert a BST to a sorted ci ...

  6. LeetCode: 109. Convert Sorted List to Binary Search Tree

    题目 Given a singly linked list where elements are sorted in ascending order, convert it to a height b ...

  7. 学习数据结构 二叉查找树(binary search tree)

    2019独角兽企业重金招聘Python工程师标准>>> 为学习 LLVM 的 ImmutableSet,其底层的实现选择为 AVL 树(平衡二叉搜索树),我不很熟悉该树,虽然大致知道 ...

  8. Recover Binary Search Tree

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  9. Lowest Common Ancestor of a Binary Search Tree(树中两个结点的最低公共祖先)

    题目描述: Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in ...

最新文章

  1. python 读取文件到字典读取顺序_python_实现dictionary按照输入顺序输出
  2. RecursionError: maximum recursion depth exceeded
  3. PCB板查短路点的一种技巧 (转载)
  4. 51Node 01组成的N的倍数
  5. Machine Learning学习计划
  6. 工具的使用——电脑的认识与使用
  7. application配置和profile隔离配置(转)
  8. Android 8.0 安装Google服务
  9. 个税系统服务器怎么设置,如何开通个税服务器地址
  10. 图片,表格末尾紧贴上方图片或表格添加脚注/备注
  11. 圆形时间html,html5 canvas实现圆形时钟代码分享
  12. 同步,异步,直流电机原理
  13. 哪个牌子的蓝牙耳机音质好?音质比较好的蓝牙耳机排名
  14. Point Estimation
  15. office 文档 在线查看
  16. mobiscroll插件滑动时间选择效果
  17. MySQL表锁了如何解锁
  18. 蓝桥杯赛前真题 Python组 Day 4
  19. plsql远程连接Oracle
  20. python算法工程师需要学什么_成为一名 AI 算法工程师,你需要具备哪些能力?...

热门文章

  1. 重庆java培训达内,重庆java培训费用
  2. 营销DMP的漫谈指北
  3. Java10Java11新特性——代码示例
  4. 5年前, 以太坊大脑送给V神一份神秘大礼; 今天, V神将它给了你...
  5. 院子中的灯光照明设施
  6. 恐怖庄园的秘密 The Secret of Grisly Manor攻略
  7. hy_interactive_tool学习笔记
  8. 用友NC系统连接不到服务器,客户端连接不到服务器 _0
  9. 没有钢琴也可实现弹奏自由?实时在Jetson上运行单阶段手指关键点模型
  10. BAT | 批处理下载ftp文件