好的,我很困惑。我使用两个Python包 - PyPDF2和SQLAlchemy。 SQLAlchemy使用python的warning.warn()发出警告,并以某种方式在PyPDF2中调用formatWarning()函数,该函数也使用python的warning.warn()。
这是SQLAlchemy或PyPDF2中的错误吗?
这是怎么发生的 - 格式警告是否有一些特殊功能?
PyPDF2将其定义为:
#custom implementation of warnings.formatwarning
def formatWarning(message, category, filename, lineno, line=None):
file = filename.replace("/", "\\").rsplit("\\", 1)[1] # find the file name
return "%s: %s [%s:%s]\n" % (category.__name__, message, file, lineno)
我的错误堆栈是 -
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/orm/strategies.py", line 613, in _emit_lazyload
% self.parent_property)
File "/usr/local/lib/python2.7/dist-packages/SQLAlchemy-0.9.7-py2.7-linux-x86_64.egg/sqlalchemy/util/langhelpers.py", line 1205, in warn
warnings.warn(msg, exc.SAWarning, stacklevel=stacklevel)
File "/usr/local/lib/python2.7/dist-packages/PyPDF2/pdf.py", line 817, in _showwarning
file.write(formatWarning(message, category, filename, lineno, line))
File "/usr/local/lib/python2.7/dist-packages/PyPDF2/utils.py", line 59, in formatWarning
file = filename.replace("/", "\\").rsplit("\\", 1)[1] # find the file name
IndexError: list index out of range
答案 0 :(得分:1)
看起来这是包PyPDF2中的一个旧错误,它覆盖了python utils._formatwarning
:
warnings.formatwarning = utils._formatwarning
最近发布的版本似乎修复了此问题,更新到最新修复了该问题。