mitsuhiko / mitsuhiko/python-geoip
TypeError: a bytes-like object is required, not 'str'
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 246
- Forks
- 50
- PR merge metrics
- No merged PRs in 30d
Description
python-geoip (1.2)
python 3.6.9
Reproduce:
from geoip import geolite2
match = geolite2.lookup('8.8.8.8')
Output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/geoip.py", line 364, in lookup
return self._get_actual_db().lookup(ip_addr)
File "/usr/local/lib/python3.6/dist-packages/geoip.py", line 350, in _get_actual_db
rv = self._load_database()
File "/usr/local/lib/python3.6/dist-packages/geoip.py", line 342, in _load_database
return mod.loader(self, sys.modules[__name__])
File "/usr/local/lib/python3.6/dist-packages/_geoip_geolite2/__init__.py", line 9, in loader
return mod.open_database(filename)
File "/usr/local/lib/python3.6/dist-packages/geoip.py", line 508, in open_database
md = _read_mmdb_metadata(buf)
File "/usr/local/lib/python3.6/dist-packages/geoip.py", line 382, in _read_mmdb_metadata
buf.size() - MMDB_METADATA_BLOCK_MAX_SIZE)
TypeError: a bytes-like object is required, not 'str'
The same issue happens using a self-provided latest DB:
from geoip import open_database
db = open_database('GeoLite2-City.mmdb')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/geoip.py", line 508, in open_database
md = _read_mmdb_metadata(buf)
File "/usr/local/lib/python3.6/dist-packages/geoip.py", line 382, in _read_mmdb_metadata
buf.size() - MMDB_METADATA_BLOCK_MAX_SIZE)
TypeError: a bytes-like object is required, not 'str'
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with geoip.py, especially open_database and _read_mmdb_metadata, then reproduce the failure with geolite2.lookup('8.8.8.8') and open_database('GeoLite2-City.mmdb') under Python 3.6. Done means both database-loading paths complete without the reported bytes-versus-string TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100