Software Development

Python Unicode Encode Errors

It’s sometimes stressful when working with string conversion in Python while coming across encoding errors. An example is the following error that was generated when I converted a JSON file into CSV so that I can analyze the data using pandas:

‘ascii’ codec can’t encode character u’\xe9′ in position 2

The JSON file was generated from an Influx DB instance via cURL. These links from Stack Overflow really helped. Please read the first two answers from each question. The second question’s most voted answer gives a detailed description on why you should not do a system wide change to utf-8 encoding as opposed to the first question’s most voted answer.

Further reading: Getting unicode right in Python

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s