Python Forum
python charmap codec can't decode byte X in position Y character maps to < undefined>
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python charmap codec can't decode byte X in position Y character maps to < undefined>
#5
Testing and fixing his code.
Here the whole run,using virtual environment.
C:\Python36
λ python -m venv geo_test

C:\Python36
λ cd geo_test

C:\Python36\geo_test
λ ls
Include/  Lib/  Scripts/  pyvenv.cfg

C:\Python36\geo_test
λ c:\python36\geo_test\Scripts\activate.bat
(geo_test) C:\Python36\geo_test
λ pip -V
pip 9.0.1 from c:\python36\geo_test\lib\site-packages (python 3.6)

(geo_test) C:\Python36\geo_test
λ pip install geotext-0.3.0-py2.py3-none-any.whl
Processing c:\python36\geo_test\geotext-0.3.0-py2.py3-none-any.whl
Installing collected packages: geotext
Successfully installed geotext-0.3.0

(geo_test) C:\Python36\geo_test
λ python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from geotext import GeoText
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "C:\Python36\geo_test\lib\site-packages\geotext\__init__.py", line 7, in <module>
   from .geotext import GeoText
 File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 87, in <module>
   class GeoText(object):
 File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 103, in GeoText
   index = build_index()
 File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 77, in build_index
   cities = read_table(get_data_path('cities15000.txt'), usecols=[1, 8])
 File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 54, in read_table
   for line in lines:
 File "C:\Python36\geo_test\lib\site-packages\geotext\geotext.py", line 51, in <genexpr>
   lines = (line for line in f if not line.startswith(comment))
 File "C:\Python36\lib\encodings\cp1252.py", line 23, in decode
   return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 165: character maps to <undefined>
Fix:
Line 45 geotext.py:
with open(filename, 'r') as f:
To:
with open(filename, 'r', encoding='utf-8') as f:
Test.
(geo_test) C:\Python36\geo_test
λ python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from geotext import GeoText
>>> places = GeoText("London is a great city")
>>> places.cities
['London']

>>> GeoText('New York, Texas, and also China').country_mentions
OrderedDict([('US', 2), ('CN', 1)])

>>> places = GeoText("Oslo is a great city")
>>> places.cities
['Oslo']
Edit:
There where 1-bug rapport about this.
So i have given this info to author of geotext on GitHub.
Reply


Messages In This Thread
RE: python charmap codec can't decode byte X in position Y character maps to < undefined> - by snippsat - Mar-21-2017, 10:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with nested maps Unkovic 10 1,511 Nov-01-2023, 03:45 PM
Last Post: Unkovic
  Python rule about the space character surrounding the equal sign ineuw 10 1,794 Sep-21-2023, 09:17 AM
Last Post: ineuw
  How do I handle escape character in parameter arguments in Python? JKR 6 1,312 Sep-12-2023, 03:00 AM
Last Post: Apoed2023
Question UnicodeEncodeError: 'ascii' codec can't encode character u'\xe8' in position 562: ord ctrldan 23 5,134 Apr-24-2023, 03:40 PM
Last Post: ctrldan
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd2 in position 16: invalid cont Melcu54 3 5,224 Mar-26-2023, 12:12 PM
Last Post: Gribouillis
  Decode string ? JohnnyCoffee 1 858 Jan-11-2023, 12:29 AM
Last Post: bowlofred
  [SOLVED] [Debian] UnicodeEncodeError: 'ascii' codec Winfried 1 1,073 Nov-16-2022, 11:41 AM
Last Post: Winfried
  UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 34: character Melcu54 7 19,521 Sep-26-2022, 10:09 AM
Last Post: Melcu54
  undefined function error JonWayn 5 1,528 Sep-11-2022, 03:38 AM
Last Post: JonWayn
  Undefined Led_Zeppelin 4 1,490 Aug-02-2022, 11:57 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020