c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
Python

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

| | python

COUNTRY INFO PROGRAM:

I want to retrieve the country information using the 'countryinfo' library. I have installed countryinfo python package using pip.

pip install countryinfo

CODE:

To get country information and print basic country information  using python, import CountryInfo,
from countryinfo import CountryInfo


def get_country_info(country_name):
try:
country = CountryInfo(country_name)
return {
'capital': country.capital(),
"Region": country.region(),
"Currencies": country.currencies(),
"Languages": country.languages(),
}
except Exception as e:
print(f"Error: {e}")

if __name__ == "__main__":
country_name = input("Enter the country name: ")
country_details = get_country_info(country_name)
print(country_details)

I got this following error while executing a python program. 

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

UnicodeDecodeError

SOLUTION:

This problem is related to the character encoding. To handle this issue use encoding utf-8.

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

VIDEO GUIDE: