我得到以下追溯
--- Logging error ---
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/logging/__init__.py", line 994, in emit
stream.write(msg)
TypeError: a bytes-like object is required, not 'str'
我不记得在这个脚本中添加任何内容并且之前有效。以下是与日志记录相关的代码
logFileMode = 'wb'
logging.basicConfig(filename='logs/download.log',format='%(levelname)s %(asctime)s - %(message)s',level=logging.DEBUG, filemode = logFileMode)
logger = logging.getLogger(__name__)
logging.info('Script started')
答案 0 :(得分:0)
谢谢您的发帖,我的Logging模块也遇到了同样的问题。 通过将FileHandler MODE更改为'a +'或'w +'而不是'ab'或'wb'[解决]。
from logging.handlers import WatchedFileHandler as Watch
import threading
self.commonLogFileName = gen_common_filename()
self.commonLogFileHandler = Watch(self.commonLogFileName, mode='a+')
self.commonLogFileHandler.setFormatter(self.format)
self.root.addHandler(self.commonLogFileHandler)
# Create new log record
self.root.log(level, dbgMsg)