UnicodeEncodeError: 'ascii' codec can't encode characters in position 9-10: ordinal not in range(128)
时间: 2023-09-28 14:07:24 浏览: 91
This error occurs when trying to encode a string containing non-ASCII characters (characters outside the range of 0-127) using the ASCII codec. ASCII is a character encoding standard that only includes 128 characters, including English letters, digits, and symbols.
To fix this error, you can encode the string using a different codec that supports non-ASCII characters, such as UTF-8. For example:
```
my_string = "Résumé"
my_encoded_string = my_string.encode('utf-8')
```
Alternatively, you can convert the non-ASCII characters to their ASCII equivalents using a library such as unidecode:
```
from unidecode import unidecode
my_string = "Résumé"
my_ascii_string = unidecode(my_string)
```
This will replace the non-ASCII characters with their closest ASCII equivalents, so "Résumé" becomes "Resume".
阅读全文