Suds ignores proxy settings

I am trying to use the Salesforce-python-toolkit tool to call web services in the Salesforce API, but I am unable to get the client to go through the proxy server. Since the toolkit is based on the top of the foam, I tried to go down to use only the foam to see if I can make it respect the proxy setting, but it doesn't work either.

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

An example of the request I made that did not finish the proxy server (just scrolling firmware or charles executed locally):

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

I tried different things with the http: // proxy using IP using the fully qualified domain name. I went through the code in pdb and see that it sets the proxy parameter. I also tried to create a client instance without a proxy, and then install it with: ws.set_options (proxy = {'HTTP': 'HTTP: // local: 8888})

Is the proxy server no longer used by foam? I do not see it being listed here http://jortel.fedorapeople.org/suds/doc/suds.options.Options-class.html , but I see it under the transport. Do I need to install it differently through transport? When I switched to pdb, it looks like he was using transport, but I'm not sure how to do this.

Thanks!

+6
source share
4 answers

I entered #suds on freenode and Xelnor / rbarrois gave a great answer! Apparently the custom foam mapping overrides urllib2's behavior to use system configuration environment variables. This decision now depends on the availability of the appropriate environment variables http_proxy / https_proxy / no_proxy.

I hope this helps someone else run into problems with proxies and foams (or other libraries using foaming). 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()) 
+14
source

I think you can do this using the urllib2 opener as shown below.

 import suds t = suds.transport.http.HttpTransport() proxy = urllib2.ProxyHandler({'http': 'http://localhost:8888'}) opener = urllib2.build_opener(proxy) t.urlopener = opener ws = suds.client.Client('file://sandbox.xml', transport=t) 
+4
source

I had several problems using Suds, although my proxy was configured correctly, I could not connect to the wsdl endpoint. After spending considerable time trying to formulate a workaround, I decided to give a soap2py shot - https://code.google.com/p/pysimplesoap/wiki/SoapClient

He worked right off the bat.

+2
source

I really managed to get it working by doing two things:

  • make sure there are keys for http and https in the proxy.
  • setting up a proxy server using set_options AFTER creating the client.

So my relevant code is as follows:

self.suds_client = suds.client.Client(wsdl) self.suds_client.set_options(proxy={'http': 'http://localhost:8888', 'https': 'http://localhost:8888'})

+2
source

Source: https://habr.com/ru/post/925355/


All Articles