Last active
September 19, 2022 07:50
-
-
Save machacekondra/eb1abd1c73024911adb2668b3cfbab30 to your computer and use it in GitHub Desktop.
Use suds soap client with local unix socket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from suds.client import Client | |
| from suds.transport.http import HttpAuthenticated, HttpTransport | |
| import http.client | |
| import socket | |
| import urllib.request | |
| class LocalSocketHttpConnection(http.client.HTTPConnection): | |
| def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |
| source_address=None, socketpath=None): | |
| super().__init__(host, port, timeout, source_address) | |
| self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
| self.sock.connect(socketpath) | |
| class LocalSocketHandler(urllib.request.HTTPHandler): | |
| def __init__(self, debuglevel=0, socketpath=None): | |
| self._debuglevel = debuglevel | |
| self._socketpath = socketpath | |
| def http_open(self, req): | |
| return self.do_open(LocalSocketHttpConnection, req, socketpath=self._socketpath) | |
| class LocalSocketHttpAuthenticated(HttpAuthenticated): | |
| def __init__(self, socketpath, **kwargs): | |
| HttpAuthenticated.__init__(self, **kwargs) | |
| self._socketpath = socketpath | |
| def u2handlers(self): | |
| handlers = HttpTransport.u2handlers(self) | |
| handlers.append(LocalSocketHandler(socketpath=self._socketpath)) | |
| return handlers | |
| localsocket = LocalSocketHttpAuthenticated(b'/tmp/.sapstream50113') | |
| client = Client('http://localhost/sapcontrol?wsdl', transport=localsocket) | |
| print(client.service.GetSystemInstanceList()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment