Reputation: 5
I am using with open
to open my json file and parse data from it, however some characters aren't ascii. I google around and found that you have to set encoding='utf8'
in with open()
, so I do this and get this error
UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 21: ordinal not in range(128)
So I figure I have to use ensure_ascii=False
but then I get this error
TypeError: 'ensure_ascii' is an invalid keyword argument for open()
As you can see by the error ensure_ascii isn't compatible with open()
but I don't know what is and I seem to be stuck and unable to find it.
The code being used
with open("languages.json", 'r', encoding='utf8') as f:
languages = json.load(f)
with open("config.json", 'r', encoding='utf8') as c:
config = json.load(c)
Upvotes: 0
Views: 1086
Reputation: 1077
I believe that utf8
is not the correct keyword, instead use utf-8
in your encoding=
Upvotes: 1