Python格式警告和交叉包装错误 [英] Python formatWarning and cross-package errors
问题描述
好的,我很困惑.我正在使用两个Python软件包-PyPDF2和SQLAlchemy. SQLAlchemy使用python的warning.warn()发出警告,并以某种方式调用PyPDF2中的formatWarning()函数,该函数也使用python的warning.warn().
Okay, I am confused. I am using two Python packages - PyPDF2 and SQLAlchemy. SQLAlchemy is raising a warning using python's warning.warn(), and somehow calling a formatWarning() function in PyPDF2, which also uses python's warning.warn().
这是SQLAlchemy或PyPDF2中的错误吗?
Is this an error in SQLAlchemy or PyPDF2?
这甚至是怎么发生的-formatWarning有一些特殊功能吗?
How does this even happen - is formatWarning some special function?
PyPDF2将其定义为:
PyPDF2 defines it as:
#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
:
It appears this was an old error in the package PyPDF2, where it was overwriting python utils._formatwarning
:
warnings.formatwarning = utils._formatwarning
最新版本似乎已解决此问题,将其更新至最新版本以解决此问题.
Recent releases appear to have fixed this, updating to the latest fixed the issue.
这篇关于Python格式警告和交叉包装错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!