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

后端 未结 29 2913
余生分开走
余生分开走 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 05:02

    We struck this error when running manage.py migrate in Django with localized fixtures.

    Our source contained the # -*- coding: utf-8 -*- declaration, MySQL was correctly configured for utf8 and Ubuntu had the appropriate language pack and values in /etc/default/locale.

    The issue was simply that the Django container (we use docker) was missing the LANG env var.

    Setting LANG to en_US.UTF-8 and restarting the container before re-running migrations fixed the problem.

提交回复
热议问题