相关疑难解决方法(0)

使用Ubuntu容器(ascii,utf-8)在docker(Python,Java,Ruby,...)中运行应用程序时出现编码问题

在我自己的PC上,应用程序运行良好,但当它部署到docker时,由于无效字符而失败.

我正在使用ubuntu:lastest容器python3,javaruby.

ruby python java locale docker

19
推荐指数
1
解决办法
1万
查看次数

Python的string.format()和Unicode

我遇到了Python的问题string.format()并将Unicode字符串传递给它.这与旧的问题类似,只是在我的情况下,测试代码在打印时爆炸,而不是在logging.info()通话中.将相同的Unicode字符串对象传递给日志记录处理程序可以正常工作.

对于较旧的%格式以及此格式,这同样失败string.format().为了确保它是问题的字符串对象,而不是打印与我的终端严重交互,我尝试在打印之前将格式化的字符串分配给变量.

def unicode_test():
    byte_string = '\xc3\xb4'
    unicode_string = unicode(byte_string, "utf-8")
    print "unicode object type: {}".format(type(unicode_string))
    output_string = "printed unicode object: {}".format(unicode_string)
    print output_string

if __name__ == '__main__':
    unicode_test()
Run Code Online (Sandbox Code Playgroud)

字符串对象似乎假设它正在获得ASCII.

% python -V
Python 2.7.2

% python ./unicodetest.py
unicode object type: <type 'unicode'>
Traceback (most recent call last):
  File "./unicodetest.py", line 10, in <module>
    unicode_test()
  File "./unicodetest.py", line 6, in unicode_test
    output_string = "printed unicode object: {}".format(unicode_string)
UnicodeEncodeError: 'ascii' codec …
Run Code Online (Sandbox Code Playgroud)

python unicode

16
推荐指数
1
解决办法
2万
查看次数

将编码参数添加到logging.basicConfig

如何添加encoding参数logging.basicConfig

我发现这个错误报告说明现在可以用于Python 3.3.我需要这个用于Python 2.7,并且bug报告说要使用自定义logging.FileHandler对象,但我无法让它工作.

python logging

10
推荐指数
3
解决办法
9918
查看次数

标签 统计

python ×3

docker ×1

java ×1

locale ×1

logging ×1

ruby ×1

unicode ×1