简体   繁体   中英

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. I have tried converting to utf-8 and encoding, but am getting the same error.

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. In the original doc, it is string .

http://pythonhosted.org/python-geoip/

I would suggest trying the official Python geoip2 API or python-geoip-yplan . The latter is a fork of python-geoip with better Python 3 support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM