我的代码:
dbFile = 'data\ip2region.db'
searcher = Ip2Region(dbFile)
def testSearch():
ip = '49.116.42.221'
if searcher.isip(ip):
data = searcher.btreeSearch(ip)
print("%s|%s" % (ip, data["region"].decode('utf-8')))
else:
print('%s|错误数据'%ip)
第一次有数据,第二次开始报错:
Traceback (most recent call last):
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 2463, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\_compat.py", line 39, in reraise
raise value
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\IZQUT\AppData\Local\Programs\Python\Python37\lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "c:\Users\IZQUT\Desktop\flask\ip.py", line 87, in index
ip_str=testSearch()
File "c:\Users\IZQUT\Desktop\flask\ip.py", line 22, in testSearch
data = searcher.btreeSearch(ip)
File "c:\Users\IZQUT\Desktop\flask\ip2Region.py", line 102, in btreeSearch
if len(self.__headerSip) < 1:
TypeError: object of type 'NoneType' has no len()
怎么回事?