【问题标题】:Python formatWarning and cross-package errorsPython 格式警告和跨包错误
【发布时间】: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

【问题讨论】:

标签: python sqlalchemy warnings pypdf


【解决方案1】:

这似乎是 PyPDF2 包中的一个旧错误,它正在覆盖 python utils._formatwarning

warnings.formatwarning = utils._formatwarning

最近的版本似乎已经解决了这个问题,更新到最新版本解决了这个问题。

【讨论】:

  • 我有版本 1.26.0(最新),但仍然有这个问题
猜你喜欢
  • 2020-02-15
  • 2018-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多