“UnicodeEncodeError: 'ascii' codec can't encode character”

前端 未结 4 1836
星月不相逢
星月不相逢 2020-12-02 19:01

I\'m trying to pass big strings of random html through regular expressions and my Python 2.6 script is choking on this:

UnicodeEncodeError: \'ascii\' codec can\'t e

4条回答
  •  渐次进展
    2020-12-02 19:40

    First of all, try installing translations for English language (or any other if needed):

    sudo apt-get install language-pack-en
    

    which provides translation data updates for all supported packages (including Python).

    And make sure you use the right encoding in your code.

    For example:

    open(foo, encoding='utf-8')
    

    Then double check your system configuration like value of LANG or configuration of locale (/etc/default/locale) and don't forget to re-login your session.

提交回复
热议问题