4

I am trying to connect to SugarCRM soap services (what's the correct terminology?) using Suds:

from suds.client import Client

url = "http://localhost/sugarcrm/soap.php?wsdl"
client = Client(url)
session = client.service.login("usr", "pwd")

But the very last line throws an exception:

ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns3="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.sugarcrm.com/sugarcrm" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Header/>
   <ns2:Body>
      <ns1:login>
         <user_auth xsi:type="ns1:user_auth">usr</user_auth>
         <application_name xsi:type="ns3:string">pwd</application_name>
      </ns1:login>
   </ns2:Body>
</SOAP-ENV:Envelope>
Traceback (most recent call last):
  File "python.py", line 5, in <module>
    session = client.service.login("usr", "pwd")
  File "/usr/lib/pymodules/python2.6/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "/usr/lib/pymodules/python2.6/suds/client.py", line 602, in invoke
    result = self.send(soapenv)
  File "/usr/lib/pymodules/python2.6/suds/client.py", line 653, in send
    result = self.failed(binding, e)
  File "/usr/lib/pymodules/python2.6/suds/client.py", line 714, in failed
    raise Exception((status, reason))
Exception: (404, u'Not Found')
tshepang
  • 10,772
  • 21
  • 84
  • 127
  • do you need to specify a port? i.e. http://localhost:8080/... or whatever port the service is on – jpm Jun 27 '11 at 22:43

3 Answers3

5

Try passing also the argument location=url to the Client constructor. Sometimes the location element in WSDLs doesn't match up with URI on the server.

client = Client(url, location=url)
bluish
  • 23,093
  • 23
  • 110
  • 171
jathanism
  • 30,623
  • 9
  • 64
  • 86
  • Great tip! I add that with some other WS (e.g. Talend Open Studio generated WS) not even `location=url` is right, but you have to discover the correct location of the endpoint and then pass to SUDS. – bluish Sep 01 '11 at 09:17
2

I was having the same issue when using a SUDS connection stub. I was always getting Exception: (404, u'Not Found') Everything else was set up fine so i just started guessing and trying.

I don't know if certain SOAP servers cause this or the fact that i need to set location by hand. The solution was to append the name of the service to the location URL. So you need to create several stubs for each distinct service used but it works:

servicename = "TestService"    

client = Client(                                                                                                                                                      
    url="foobar.wsdl",                                                                                                                                              
    location = "http://soap.example.com/foobar/" + servicename ,
)

result = client[servicename]["TestServicePort"].TestServiceFunction()
print(result)

This is not intended behavior, because the SUDS should to this by itself (i think), but it was the only option to get past this bug. Maybe its caused by the fact i needed to specify the Client.location attribute by hand, and so SUDS does not change it anymore regardless of what service i need to call.

Since it took me a while to find out, I bet this helps some poor guy :D

regards, Michael

mschmoock
  • 17,114
  • 5
  • 30
  • 32
  • I know this was 7 years ago... but this helped me solve my issue. The key seemed to be setting the `location` when instantiating the `Client`. I just set `url` and `location` to the same thing. – Chris Oct 13 '20 at 01:19
1

If you aren't hooked on using Suds, you should try the Python library we've been working on for connecting to SugarCRM via Python. It goes over REST versus SOAP, which should make access much faster.

Check it out at https://github.com/sugarcrm/python_webservices_library

jmertic
  • 2,193
  • 1
  • 12
  • 8
  • I was only getting started actually. Thanks a lot. But you guys haven't yet marketed this yet (I would expect it [here](http://developers.sugarcrm.com/opensource)), or is it too immature? – tshepang Jun 28 '11 at 01:21
  • It's a new project, that I'm hoping a community can form around and help build it to be an excellent library. If you'd like to help participate with your Python expertise, please let me know. – jmertic Sep 01 '11 at 13:08