-
-
Save MaxMorais/a066b2350ed2f7c28c2b to your computer and use it in GitHub Desktop.
brainstorming on suds + python-requests thinamabob, MIT-licensed
This file contains 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.transport import Transport, Reply | |
from suds.client import Client | |
import requests | |
from StringIO import StringIO | |
class RequestsTransport(Transport): | |
def open(self, request): | |
""" suds assumes urllib2 which doesn't have keepalives so things can go royally wrong if it doesn't | |
read the entire request. Hence, read it all up and give a StringIO object instead. | |
Error handling needed | |
""" | |
verify_ssl = self.options.get("verify_ssl", True) | |
r = requests.get(url=request.url, headers=request.headers, | |
verify=verify_ssl) | |
return StringIO(r.content) | |
def send(self, request): | |
""" Just a naivistic suds.transport.Request->requests->suds.transport.Reply wrapper. This is | |
missing proper error handling | |
""" | |
verify_ssl = self.options.get("verify_ssl", True) | |
r = requests.post(url=request.url, data=request.message, headers=request.headers, | |
verify=verify_ssl) | |
return Reply(code=r.status_code, headers=r.headers, message=r.content) | |
class RequestsClient(Client): | |
def __init__(self, url, **kwargs): | |
kwargs.setdefault("transport", RequestsTransport) | |
Client.__init__(self, url, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment