【发布时间】:2014-08-28 14:54:53
【问题描述】:
好吧,我很困惑。我正在使用两个 Python 包——PyPDF2 和 SQLAlchemy。 SQLAlchemy 正在使用 python 的 warning.warn() 发出警告,并以某种方式调用 PyPDF2 中的 formatWarning() 函数,该函数也使用 python 的 warning.warn()。
这是 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 的问题:github.com/mstamy2/PyPDF2/issues/67
标签: python sqlalchemy warnings pypdf