Python ftplib - 有什么方法可以关闭它吗?
我正在用 python 编写一个测试工具,作为测试的一部分,我需要初始化 FTP 服务器并上传各种文件。我正在使用 ftplib,一切正常。我遇到的唯一问题是,我看到控制台窗口中出现大量 FTP 文本,与我的测试结果混合在一起,这使得扫描结果变得相当棘手。我还没有找到关闭 ftp lib 并阻止这种情况发生的方法,有人知道如何阻止这种情况吗?
I am writing a test harness in python and as part of the testing I need to initialise an FTP server and upload various files. I am using ftplib and everything is working ok. The only problem I have is that I am seeing loads of FTP text appearing in the console window intermixed with my test results, which makes scanning the results quite tricky. I haven't found a way to shut ftp lib up and stop this happening, does anyone know how to stop this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要手动将空(或以其他方式自定义)回调传递给至少 retrlines 和 dir。默认情况下,它们打印到标准输出(设计有问题)。默认情况下,类似的调用(可能用于调试)
将打印到您的终端。删除它们或使用自定义回调:
retrlinesCallback
和dirCallback
函数可以具有逻辑,例如仅在启用调试时才打印到终端。还有一个 set_debuglevel 选项。默认值为 0(不进行调试),但可能在代码中的某个位置设置得更高。
You need to manually pass empty (or otherwise customized) callbacks to at least retrlines and dir. By default they print to stdout (questionable design). By default calls (probably for debugging) like
will print to your terminal. Remove them or use custom callbacks:
retrlinesCallback
anddirCallback
functions could have logic to e.g. print to the terminal only if debugging is enabled.There is also a set_debuglevel option. The default is 0 (no debugging), but it might be set higher somewhere in the code.