[英]Using a python2 library with python3
I'm using python3 and geolite2, but I'm finding that I cannot pass in the IP address that I want to look up and I get the following error. 我正在使用python3和geolite2,但发现无法传递我要查找的IP地址,但出现以下错误。 I have tried converting to utf-8 and encoding, but am getting the same error.
我曾尝试转换为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 = geolite2.lookup(ip_bytes)
or 要么
loc = geolite2.lookup(ip_address.encode())
Following error: 以下错误:
TypeError: 'str' does not support the buffer interface
What format should the IP go in as. IP应该以什么格式输入。 In the original doc, it is
string
. 在原始文档中,它是
string
。
http://pythonhosted.org/python-geoip/ http://pythonhosted.org/python-geoip/
I would suggest trying the official Python geoip2 API or python-geoip-yplan . 我建议尝试使用官方的Python geoip2 API或python-geoip-yplan 。 The latter is a fork of python-geoip with better Python 3 support.
后者是python-geoip的分支,具有更好的Python 3支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.