Suds ignoring proxy setting

2024/10/3 14:26:58

I'm trying to use the salesforce-python-toolkit to make web services calls to the Salesforce API, however I'm having trouble getting the client to go through a proxy. Since the toolkit is based on top of suds, I tried going down to use just suds itself to see if I could get it to respect the proxy setting there, but it didn't work either.

This is tested on suds 0.3.9 on both OS X 10.7 (python 2.7) and ubuntu 12.04.

an example request I've made that did not end up going through the proxy (just burp or charles proxy running locally):

import suds
ws = suds.client.Client('file://sandbox.xml',proxy={'http':'http://localhost:8888'})
ws.service.login('user','pass')

I've tried various things with the proxy - dropping http://, using an IP, using a FQDN. I've stepped through the code in pdb and see it setting the proxy option. I've also tried instantiating the client without the proxy and then setting it with:ws.set_options(proxy={'http':'http://localhost:8888'})

Is proxy not used by suds any longer? I don't see it listed directly here http://jortel.fedorapeople.org/suds/doc/suds.options.Options-class.html, but I do see it under transport. Do I need to set it differently through a transport? When I stepped through in pdb it did look like it was using a transport, but I'm not sure how.

Thank you!

Answer

I went into #suds on freenode and Xelnor/rbarrois provided a great answer! Apparently the custom mapping in suds overrides urllib2's behavior for using the system configuration environment variables. This solution now relies on having the http_proxy/https_proxy/no_proxy environment variables set accordingly.

I hope this helps anyone else running into issues with proxies and suds (or other libraries that use suds). https://gist.github.com/3721801

from suds.transport.http import HttpTransport as SudsHttpTransport class WellBehavedHttpTransport(SudsHttpTransport): """HttpTransport which properly obeys the ``*_proxy`` environment variables.""" def u2handlers(self): """Return a list of specific handlers to add. The urllib2 logic regarding ``build_opener(*handlers)`` is: - It has a list of default handlers to use - If a subclass or an instance of one of those default handlers is given in ``*handlers``, it overrides the default one. Suds uses a custom {'protocol': 'proxy'} mapping in self.proxy, and adds a ProxyHandler(self.proxy) to that list of handlers. This overrides the default behaviour of urllib2, which would otherwise use the system configuration (environment variables on Linux, System Configuration on Mac OS, ...) to determine which proxies to use for the current protocol, and when not to use a proxy (no_proxy). Thus, passing an empty list will use the default ProxyHandler which behaves correctly. """ return []client = suds.client.Client(my_wsdl, transport=WellBehavedHttpTransport())
https://en.xdnf.cn/q/70716.html

Related Q&A

CSV to JSON script

I took this script from here: import csv from itertools import izip f = open( /django/sw2/wkw2/csvtest1.csv, r ) reader = csv.reader( f ) keys = ( "firm_url", "firm_name", "fir…

Accessing an ALREADY running process, with Python

Question: Is there a way, using Python, to access the stdout of a running process? This process has not been started by Python.Context: There is a program called mayabatch, that renders out images fro…

sum up two pandas dataframes with different indexes element by element

I have two pandas dataframes, say df1 and df2, of some size each but with different indexes and I would like to sum up the two dataframes element by element. I provide you an easy example to better und…

Urwid: make cursor invisible

Im using urwid, which is a Python "framework" for designing terminal user interfaces in ncurses. Theres one thing though that Im not able to do in urwid that was easy in curses - make the cur…

How do I use scipy.weave.inline together with external C libraries?

I am trying to understand weave.inline to wrap C code in my Python programs. The code below simply takes the Numpy array and multiplicates all of its elements by 2.inl.py import numpy import scipy.weav…

sqlalchemy multiple foreign keys to same table

I have a postgres database that looks something like this:Table "public.entities"Column | Type | Modifiers ---------------+---…

Django - Return a file from Root folder via a URL

I purchased a SSL cert online and now ind the mid of verifying my host. How it works is:It gives me a file I have to make that file accessible through a specific URL on my host. If the content of the f…

Flask deployement on lighttpd and raspberry pi

Im trying to deploy a hello flask app to a raspberry pi using lighttpd fastCGI.I followed the instructions on the http://flask.pocoo.org/docs/0.10/deploying/fastcgi/ to the best of my abilityHere is my…

Django admin asks for login after every click

Im working on a Django app hosted on Heroku. Im able to login to the admin with my username, password. But on every single click (or on each click after a few seconds) it redirects me to the login page…

Change numerical Data to Categorical Data - Pandas [duplicate]

This question already has answers here:How to create new values in a pandas dataframe column based on values from another column(2 answers)Closed 6 years ago.I have a pandas dataframe which has a numer…