tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
1.01k stars 223 forks source link

UnicodeDecodeError: 'charmap' codec can't decode #178

Closed jlluch closed 4 years ago

jlluch commented 5 years ago

Hi, I am using a repository with multiple files, and parsing fails with some files:

gpx = gpxpy.parse(gpxfile)

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\gpxpy__init__.py", line 36, in parse parser = mod_parser.GPXParser(xml_or_file)

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\gpxpy\parser.py", line 58, in init self.init(xml_or_file)

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\gpxpy\parser.py", line 70, in init text = xml_or_file.read() if hasattr(xml_or_file, 'read') else xml_or_file

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\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 0x9d in position 609: character maps to

I don't know how to read these files, Any ideas?? Thx in advance.

tomsix commented 4 years ago

I had the same issue but solved it by adding the file encoding

file = open('your-file', encoding='utf-8')
gpx = gpx.parse(file)