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

后端 未结 29 2816
余生分开走
余生分开走 2020-11-21 04:43

I\'m having problems dealing with unicode characters from text fetched from different web pages (on different sites). I am using BeautifulSoup.

The problem is that

29条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-11-21 04:59

    In shell:

    1. Find supported UTF-8 locale by the following command:

      locale -a | grep "UTF-8"
      
    2. Export it, before running the script, e.g.:

      export LC_ALL=$(locale -a | grep UTF-8)
      

      or manually like:

      export LC_ALL=C.UTF-8
      
    3. Test it by printing special character, e.g. :

      python -c 'print(u"\u2122");'
      

    Above tested in Ubuntu.

提交回复
热议问题