zeep-禁用警告“强制肥皂:地址位置到HTTPS”

问题描述 投票:7回答:2

我正在使用zeep包来访问https上的某些API,并且在每个连接上它都会打印出警告(到stderr):

Forcing soap:address location to HTTPS

某些搜索我确实发现,负责的行是this,这意味着这是模块的日志记录级别的结果。更改日志级别似乎需要编辑this file

这对我来说是一个糟糕的解决方案,因为我希望能够在运行时关闭此警告,因为使用此软件包的应用程序将是冻结的应用程序(exe)。

如果相关,这些是显示该警告所需的最少行(尽管显然,此处的域是虚构的域,用户名和密码也是如此:]

import zeep
client = zeep.CachingClient('https://api.somedomain.com/Services/ApiService.svc?singleWsdl')
client.service.VerifyLogin('user', 'pass')

我知道zeep客户端可以设置为不强制使用https,但是我认为这样做会使连接的安全性降低? (毕竟,我将用户名和密码传递为不带https的明文)

python python-3.x logging wsdl zeep
2个回答
4
投票

经过几天的研究,我终于能够自己解决这个问题。我没有意识到可以从导入的模块更改日志记录级别。我在代码的开头(导入后)添加了这一行,并解决了该问题:

import logging
logging.getLogger('zeep').setLevel(logging.ERROR)

希望这可以帮助遇到相同问题的其他人


2
投票

警告上下文管理器如何?

您可以做类似的事情,这在我过去使用过

import zeep
import warnings

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter('always') 
    # this filters all warnings, and the context manager records them
    # your code is here:
    client = zeep.CachingClient('https://api.somedomain.com/Services/ApiService.svc?singleWsdl')
    client.service.VerifyLogin('user', 'pass')

    # now you want to verify you didn't ignore a different warning
    # here's an idea of how to verify:
    assert len(w) == 1, "More than one warning caught!"
    assert isinstance(w[0], WarningCategoryItShouldBe)


© www.soinside.com 2019 - 2024. All rights reserved.