How to use a SOCKS proxy with Suds

Posted in blogposts with tags python howto - - Reading time: 1 mins.

The proxy option in Suds (a Python SOAP library) doesn’t seem to work. After searching for an answer to no avail I decided to ask ChatGPT.

It came up with a working answer right away: use pysocks and monkeypatch a default proxy:

from suds.client import Client
import socks
import socket

# Configure SOCKS proxy
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "your_proxy_host", your_proxy_port)
socket.socket = socks.socksocket

# Example SOAP client initialization
url = 'http://example.com/your_wsdl_url?wsdl'
client = Client(url)

# Now you can use the 'client' object to make SOAP requests

A useful answer for all of us that are stuck with Suds. For new projects I recommend the use of Zeep.

Resources:

Written by Denick