将python2库与python3一起使用
我使用的是python3和geolite2,但是我发现我无法传递我想要查找的IP地址,我得到了以下错误。我曾尝试转换为utf-8和编码,但得到了相同的错误将python2库与python3一起使用,python,python-3.x,geolocation,ip,Python,Python 3.x,Geolocation,Ip,我使用的是python3和geolite2,但是我发现我无法传递我想要查找的IP地址,我得到了以下错误。我曾尝试转换为utf-8和编码,但得到了相同的错误 from geoip import geolite2 ip_address = request.access_route[0] or request.remote_addr print(">>>", ip_address) ip_bytes = ip_address.encode('utf-8') loc = geolit
from geoip import geolite2
ip_address = request.access_route[0] or request.remote_addr
print(">>>", ip_address)
ip_bytes = ip_address.encode('utf-8')
loc = geolite2.lookup(ip_bytes)
或
以下错误:
TypeError: 'str' does not support the buffer interface
IP应该采用什么格式。在原始单据中,它是字符串
我建议试试官方的或官方的。后者是PythonGeoIP的分支,具有更好的Python3支持
TypeError: 'str' does not support the buffer interface