Hi!
Does anyone have any idea why countryinfo package returns the following charmap error message when calling an CountryInfo object?
from countryinfo import CountryInfo
country = CountryInfo('France')
country.region()
File "...\AppData\Local\Programs\Python\Python37\lib\encodings\cp1257.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0xa1 in position 47: character maps to <undefined>
Try to set encoding to either UTF-8 or UTF-16 - take a look
at this PEP
PS Looks like your default encoding is CP1257
Open
countryinfo.py
in ....\site-packages\countryinfo folder.
Line 30 add encoding to open:
country_info = json.load(open(file_path, encoding='utf-8'))
Save change.
E:\div_code\new
λ ptpython
>>> from countryinfo import CountryInfo
>>> country = CountryInfo('France')
>>> country.capital()
'Paris'
I guess he has not testet on Windows,if not specify encoding it will sometimes on Windows fall back to charmap CP1257 encoding.
You can post this in issus Repo
countryinfo.
PyCharm console:
>>> sys.getdefaultencoding()
'utf-8'
So, why does it complain about CP1257 encoding? Any idea to use some other countryinfo packages to find information for a specified country?
(Sep-16-2018, 09:00 AM)mkaru Wrote: [ -> ]So, why does it complain about CP1257 encoding?
Yes the default encoding is
utf-8
,but when it try open the .json files it guess wrong.
(Sep-16-2018, 09:00 AM)mkaru Wrote: [ -> ]Any idea to use some other countryinfo packages to find information for a specified country?
Why don't you make change that i postet to line 30?
# Orginal
country_info = json.load(open(file_path))
# Fix
country_info = json.load(open(file_path, encoding='utf-8'))
Then the package work fine.
I can re build it for you with the fix.
pip uninstall countryinfo
Download
countryinfo-0.1.0-py3-none-any
Then:
pip install countryinfo-0.1.0-py3-none-any.whl
I made changes in countryinfo.py file but no positive result:
SyntaxError: invalid syntax
country = CountryInfo('France')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "...\site-packages\countryinfo\countryinfo.py", line 30, in __init__
country_info = json.load(open(file_path, encoding='utf-8'))
File "...\Python\Python37\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "...\Python\Python37\lib\encodings\cp1257.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0xa1 in position 47: character maps to <undefined>
I think you have misunderstand.
File "...\site-packages\countryinfo\countryinfo.py"
This should point to your root python installation,i just use
...\site-packages\countryinfo
to point the file.
...
should be where your Python 3.7 is installed.
Here with change to line 30 done.
C:\Users\Tom
λ python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from countryinfo import CountryInfo
>>>
>>> country = CountryInfo('France')
>>> country.capital()
'Paris'
>>> exit()
Now i remove
encoding='utf-8'
from line 30.
C:\Users\Tom
λ python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from countryinfo import CountryInfo
>>>
>>> country = CountryInfo('France')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python37\lib\site-packages\countryinfo\countryinfo.py", line 30, in __init__
country_info = json.load(open(file_path))
File "C:\python37\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\python37\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 49: character maps to <undefined>
You see it point to my python installation
File "C:\python37\lib\site-packages\countryinfo\countryinfo.py"
Also i made change to
countryinfo.py
in this location.