8

I'm using the zeep package to access some API on https, and on every connection it prints out a warning (to stderr):

Forcing soap:address location to HTTPS

Some searching I did turned up that the line responsible is this, which implies that this the result of the logging level of the module. Changing the log level seems to require editing this file.

This is a bad solution for me because I want to be able to turn this warning off at run time, because the app using this package will be a frozen app (an exe).

If that's relevant, these are the minimum lines required to display that warning (although obviously, the domain here is a fictional one, and so are the user and password):

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

I know zeep clients can be set to not force https, but I assume that would make the connection less secure? (after all, I'm passing usernames and passwords as clear text without https)

Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62

3 Answers3

8

After a few days of research I've finally been able to solve this on my own. I didn't realize logging levels can be changed from imported modules. I added this line at the start of my code (after imports) and it fixed the issue:

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

Hope this helps other people that encounter the same problem

Ofer Sadan
  • 11,391
  • 5
  • 38
  • 62
5

If you want to be a bit more specific with log level switch, in order not to miss other warnings in zeep module as a whole, you could set it alternatively like this below:

logging.getLogger('zeep.wsdl.bindings.soap').setLevel(logging.ERROR)

That will prevent warning messages only for the soap binding class, but not for the rest.

Mauro Ribeiro
  • 66
  • 2
  • 3
2

How about the warnings context manager?

you can do something like this, which I've used in the past

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)


Nate
  • 81
  • 3
  • 1
    Thank you for this, but sadly it doesn't work. I'm guessing this isn't really a warning being "raised" as much as it is a simple logging action – Ofer Sadan Nov 06 '19 at 19:37