首页 > 解决方案 > 使用 Scapy 生成数据包的 PDF 时如何抑制 PyX 警告消息?

问题描述

我正在使用 Scapy 的pdfdump方法生成一个数据包的 PDF :

from scapy.layers.inet import ICMP, IP

packet = IP(dst="192.168.111.1") / ICMP()
packet.pdfdump("report.pdf")

PyX执行此代码时,会从库中打印出大量消息。

PyX executes tex with args ['--output-directory', '/tmp/pyx1ojf7_d9'] located at /usr/bin/tex
PyX filelocator found 10pt.lfs by method internal
PyX executes kpsewhich with args ['--format', 'vf', 'cmss10'] located at /usr/bin/kpsewhich
PyX filelocator failed to find cmss10 of type ('vf',) and extensions {'', '.vf'}
PyX executes kpsewhich with args ['--format', 'tfm', 'cmss10'] located at /usr/bin/kpsewhich
PyX filelocator found cmss10 by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmss10.tfm
PyX executes kpsewhich with args ['--format', 'vf', 'cmtt10'] located at /usr/bin/kpsewhich
PyX filelocator failed to find cmtt10 of type ('vf',) and extensions {'', '.vf'}
PyX executes kpsewhich with args ['--format', 'tfm', 'cmtt10'] located at /usr/bin/kpsewhich
PyX filelocator found cmtt10 by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmtt10.tfm
PyX executes kpsewhich with args ['--format', 'map', 'pdftex.map'] located at /usr/bin/kpsewhich
PyX filelocator found pdftex.map by method kpsewhich at /var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map
PyX executes kpsewhich with args ['--format', 'type1 fonts', 'cmss10.pfb'] located at /usr/bin/kpsewhich
PyX filelocator found cmss10.pfb by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmss10.pfb
PyX executes kpsewhich with args ['--format', 'afm', 'cmss10'] located at /usr/bin/kpsewhich
PyX filelocator found cmss10 by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/afm/public/amsfonts/cm/cmss10.afm
PyX executes kpsewhich with args ['--format', 'type1 fonts', 'cmtt10.pfb'] located at /usr/bin/kpsewhich
PyX filelocator found cmtt10.pfb by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb
PyX executes kpsewhich with args ['--format', 'afm', 'cmtt10'] located at /usr/bin/kpsewhich
PyX filelocator found cmtt10 by method kpsewhich at /usr/share/texlive/texmf-dist/fonts/afm/public/amsfonts/cm/cmtt10.afm

有没有办法禁用或抑制这些消息,以免它们被打印出来?PyX手册没有太多关于如何调整这些消息的详细程度的内容。

标签: pythonpython-3.xpdfscapypyx

解决方案


此输出是使用标准 python 日志框架在日志级别 logging.INFO 创建的。默认情况下,此类日志记录输出被静音,因为默认值为 logging.WARNING (IIRC)。无论如何,只需调整您的日志记录级别,以防止通知打扰您。此外,您可以查看 pyxinfo 调用,这是 PyX 提供的启用此输出的解决方案。(也许您正在使用的库在某处调用它,并且您想禁用它。)请注意,PyX 的这种行为也记录在http://pyx.sourceforge.net/manual/text.html#debugging


推荐阅读