如果我使用 heroku run
连接到 Heroku worker dyno(例如,heroku run python
用于交互式 Python session ),任何通过此显示 Unicode 字符的尝试都会导致一个UnicodeEncodeError
本地:
$ python
Python 2.7.1 (r271:86832, Jun 25 2011, 05:09:01)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'\xa3'
£
通过heroku run
:
$ heroku run python
Running python attached to terminal... up, run.1
Python 2.7.2 (default, Oct 31 2011, 16:22:04)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'\xa3'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 0: ordinal not in range(128)
>>>
现在,如果我 heroku run bash
并使用 echo
尝试显示内容,一切似乎都很好(除了我选择的本地字体!):
$ heroku run bash
Running bash attached to terminal... up, run.2
~ $ echo -e "\xa3"
?
我假设我做错了什么/遗漏了什么,但有点迷失了什么,或者进一步的调查。
最佳答案
我相信这会解决您的问题:
$ heroku config:set LANG=en_US.UTF-8
或者,如果在您尝试运行它之后,heroku 提示您需要提供 app 参数:
$ heroku config:set LANG=en_US.UTF-8 -a <app_name>
关于python - Unicode 显示问题 (UnicodeEncodeError) 通过 "heroku run python",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9908654/