UnicodeEncodeError:' ascii'编解码器无法对位置1171-1176中的字符进行编码:序数不在范围内(128)

时间:2017-07-21 10:40:19

标签: python twitter encoding

我正在尝试将我的所有Twitter订阅导出为OPML,但不断收到此错误:

Traceback (most recent call last):
   File "twopy.py", line 103, in <module>
    template.render(feeds = feeds)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1171-
1176: ordinal not in range(128)

要点:https://gist.github.com/melekes/ab883732050e577cd7890b4953847529

我已尝试设置env vars LC_ALL/LANG并将encode('utf-8')添加到feeds,如:

'name': u['name'].encode('utf-8'),
'feed_url': urljoin(r.url, m.attrib.get('href')).encode('utf-8'),
'html_url': r.url.encode('utf-8')

此外,我已尝试将.encode('utf-8')添加到TEMPLATE。还有其他想法吗?有这样的问题,但我只是坚持这一点,抱歉。

谢谢你的时间。

1 个答案:

答案 0 :(得分:0)

试试这个: unicode(your_str, 'utf-8', errors="ignore")