嗨,我遇到了以下代码的问题。
PS:它可以在我的本地计算机上正常工作,但面临服务器中的问题。
import geoip2.database
def get_geo_city_from_ip(ip="103.148.20.109"):
try:
reader = geoip2.database.Reader('GeoLite2-City.mmdb')
response = reader.city(ip)
city=response.city.name
reader.close()
return city
except Exception as e:
return None
a = get_geo_city_from_ip()
print("City ####",a)
错误
Traceback (most recent call last):
File "test.py",line 2,in <module>
import geoip2.database
File "/var/www/html/geo/test/lib/python3.5/site-packages/geoip2/database.py",line 10,in <module>
import maxminddb
File "/var/www/html/geo/test/lib/python3.5/site-packages/maxminddb/__init__.py",line 5,in <module>
import maxminddb.reader
File "/var/www/html/geo/test/lib/python3.5/site-packages/maxminddb/reader.py",line 36
_buffer: Union[bytes,FileBuffer,"mmap.mmap"]
^
SyntaxError: invalid syntax
软件包和版本 的Python 3.5.2 aiohttp == 3.6.2 异步超时== 3.0.1 attrs == 20.2.0 证书== 2020.6.20 chardet == 3.0.4 geoip2 == 4.0.2 idna == 2.10 idna-ssl == 1.1.0 maxminddb == 2.0.2 multidict == 4.7.6 pkg-resources == 0.0.0 要求== 2.24.0 simplegeoip2 == 1.0.2 键入扩展名== 3.7.4.3 urllib3 == 1.25.10 yarl == 1.5.1