'Zeep - turn off host verification

I am using Python zeep to make a SOAP request. For SSL verification, HostHeaderSSLAdapter was added as my URL https://dev_alias:8096/some_soap, contains an alias rather than the actual host name.

This below code with requests works OK. So I would assume session is correct.

import requests
from requests_toolbelt.adapters import host_header_ssl
from zeep.transports import Transport
from zeep import Client, Settings

url = 'https://dev_alias:8096/some_soap'
params = {'param1': 'value1'}

session = requests.Session()
session.verify = 'CertBundle.pem'
session.mount('https://', host_header_ssl.HostHeaderSSLAdapter())

headers = {'SOAPAction': '""', 'Content-Type': 'text/xml; charset=utf-8'}
message = b"<?xml version=\'1.0\' encoding=\'utf-8\'?>....</soap-env:Envelope>"

session.post(url, data=message, headers=headers)

However, when the same session is used for zeep's Transport, this code fails.

transport = Transport(session=session)
client = Client(url, transport=transport)
client.service.some_service(params)

SSLError: HTTPSConnectionPool(host='actual_hostname', port=8096): 
Max retries exceeded with url: /some_soap (Caused by SSLError(CertificateError(
"hostname 'actual_hostname' doesn't match 'dev_alias'",),))

How can I turn off host name verification with zeep? Using zeep version 3.4.0 0 and requests 2.22.0



Solution 1:[1]

for testing purposes maybe you can disable ssl verification as explained here https://python-zeep.readthedocs.io/en/master/transport.html

In this case, change your session.verify line to

session.verify = False

Note that you almost certainly don't want to do this in a production system.

Solution 2:[2]

Might be a bit late to the party, but just to provide a full code snippet expanding on Andreas answer:

from zeep import Client
from zeep.transports import Transport

url = 'https://dev_alias:8096/some_soap'

# create a custom transport object turn off verification in it's session
transport = Transport()
transport.session.verify = False

client = Client(url, transport=transport)
client.service.some_service()

I had some issues figuring out the correct syntax myself, hope this helps.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thayne
Solution 2 Leon Menkreo