好吧,我很困惑。我使用的是两个Python包——PyPDF2和SQLAlchemy。SQLAlchemy正在使用python的warning.warn()发出警告,并以某种方式调用PyPDF2中的formatWarning()函数,该函数也使用python的warning.warnn().
这是SQLAlchemy或PyPDF2中的错误吗?
这是怎么发生的?formatWarning是某种特殊功能吗?
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
这似乎是PyPDF2包中的一个旧错误,它覆盖了python utils._formatwarning
:
warnings.formatwarning = utils._formatwarning
最近的版本似乎已经解决了这个问题,更新到了最新的版本。