Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
brainstorming on suds + python-requests thinamabob, MIT-licensed
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)
@multivoxmuse

This comment has been minimized.

Copy link

commented Apr 22, 2014

This is great work, it looks like it will be perfect for a project at work. Do you have an example of how it should be used in conjunction with suds? It looks like the open and send methods are expecting a 'request' object, so are you to use suds to create the requests object then send it to the methods of RequestsTransport subclass?

@manelclos

This comment has been minimized.

Copy link

commented Jul 23, 2014

I tried this gist with a suds 0.4 and it failed.

I tried lots of SUDS versions and forks, and finally got to find one that works with proxies, https and authenticated services, find it here:

https://github.com/unomena/suds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.