Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 49: character maps to <undefined>

I am creating a certain function that can give me information regarding the ISS (International Space Station) and a given location (in decimal coordinates) that can vary, depending on the input. But when I use this:

print(ubicacion.raw['address']['country'],",",ubicacion.raw['address']['city'])

It works, but for certain countries, and for example when I try with the coordinates Canberra, it displays the following info:

Corinna Street, Phillip, District of Woden Valley, Australian Capital Territory, 2606, Australia

and since it doesn't provide the city, when I use the key "city", I obviously get an error, since it doesn't exist in that list.

So one solution that I got in my mind was that since at least I will always get the country, maybe I could use another function, that based on the country, I could get the capital city, which is the one I need and it exists, I used "CountryInfo" (from countryinfo import CountryInfo). The problem is, that when I try to use it, I get the following error:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 49: character maps to

I have already searched for similar questions and many people suggest to specify the encoding, but it seems to not work with geopy. since I tried this:

countryinfo=CountryInfo(country,encoding="utf8") 

and I got this error:

TypeError: init() got an unexpected keyword argument 'encoding'

like image 295
Felipe Avatar asked Jun 04 '19 16:06

Felipe


1 Answers

Referenced from: https://python-forum.io/Thread-Countryinfo-package-charmap-error

from @snippsat's answer Sep-14-2018, 11:37 AM

Open countryinfo.py in ..Lib\site-packages\countryinfo folder. Change the line to:

country_info = json.load(open(file_path, encoding='utf-8'))

It works for me.

like image 194
Mark K Avatar answered Oct 03 '22 04:10

Mark K