Skip to main content
 首页 » 编程设计

Python 日志记录模块 AttributeError : 'str' object has no attribute 'write'

2024年10月17日9lyhabc

我正在使用 Tornado,在我的应用程序中我导入了logging,这样我就可以记录一些关于服务器的信息。

我把这个:

logging.config.dictConfig(web_LOGGING) 

就在之前:

tornado.options.parse_command_line() 

但是当我运行服务器并单击任何链接时,出现以下错误:

Traceback (most recent call last): 
  File "/usr/lib/python2.7/logging/__init__.py", line 874, in emit 
    stream.write(fs % msg) 
AttributeError: 'str' object has no attribute 'write' 
Logged from file web.py, line 1946 

这是什么原因造成的?

我已经更改到另一个目录以避免命名空间冲突。

请您参考如下方法:

Psychic 调试说 web_LOGGING 有一个名为 stream 的键和一个 str 值(可能是一个文件路径); stream is only for already opened files, if you want to pass a file path, it's passed as filename .