UnicodeEncodeError with character u'\u2013

dcraven

I am receiving the below error with the dash character "-"

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 38: ordinal not in range(128)

I have tried using the following: skills.encode('utf-8') but I still get the error. Below is my code in which I am trying to write to csv.

 writer.writerow([name.encode('utf-8'),
                 heading.encode('utf-8'),
                 location.encode('utf-8'),
                 education.encode('utf-8'),
                 summary,
                 currentRole,
                 allRoles,
                 companiesFollowed,
                 groups,
                 skills.encode('utf-8')])
Adam Smith

You can specify one of a number of settings to str.encode under the errors keyword. More info can be found in the docs but I'd recommend you use the 'replace' error handler.

writer.writerow([name.encode('utf-8', errors='replace'),
    heading.encode('utf-8', errors='replace'),
    location.encode('utf-8', errors='replace'),
    education.encode('utf-8', errors='replace'),
    summary,
    currentRole,
    allRoles,
    companiesFollowed,
    groups,
    skills.encode('utf-8', errors='replace')])

This will end up making a bytes object with a ? in place of each unencodable code point.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

UnicodeEncodeError: 'latin-1' codec can't encode character '\u2013' (writing to PDF)

python 3.2 UnicodeEncodeError: 'charmap' codec can't encode character '\u2013' in position 9629: character maps to <undefined>

python 3.2 UnicodeEncodeError: 'charmap' codec can't encode character '\u2013' in position 9629: character maps to <undefined>

UnicodeEncodeError: 'latin-1' codec can't encode character '\u2013' in position 88: ordinal not in range(256)

Ansible 'ascii' codec can't encode character u'\u2013'

UnicodeEncodeError: 'charmap' codec can't encode character '\u2264'

Pandas.to_csv gives error 'ascii' codec can't encode character u'\u2013' in position 8: ordinal not in range(128)

Unicode Encode Error 'latin-1' codec can't encode character u'\u2013' in position 4939: ordinal not in range(256)

UnicodeEncodeError: 'ascii' codec can't encode character u'\u03c0'

UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2014'

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 47: ordinal not in range(128)

Python Error; UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026'

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2019' in position 6: ordinal not in range(128)

UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 15564: ordinal not in range(128)

u2013 error with openpyxl - python 2.7

UnicodeEncodeError: 'charmap' codec can't encode character '\u2010': character maps to <undefined>

UnicodeEncodeError: 'charmap' codec can't encode character '\u2080' in position 28: character maps to <undefined>

UnicodeEncodeError: 'ascii' codec can't encode character u'\xef' in position 0: ordinal not in range(128)

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)

UnicodeEncodeError: 'latin-1' codec can't encode character '\u03bc'

Python : UnicodeEncodeError: 'charmap' codec can't encode character '\u2190' in position 2936

python post request throws UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0'

UnicodeEncodeError: 'charmap' codec can't encode character '\u010d'

UnicodeEncodeError : 'ascii' codec can't encode character u'\xd7' while saving and accessing Jupyter notebook

UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 34: ordinal not in range(128)

UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f937' in position 0: character maps to <undefined>

UnicodeEncodeError: 'decimal' codec can't encode character u'\x00' in position 8: invalid decimal Unicode string

How to fix "UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 3656: ordinal not in range(128)" error in Python