Why I get "Exception: (404," Not Found ") with Suds

I'm trying to connect soap services to SugarCRM (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') 
+4
source share
3 answers

Try passing the location=url argument to the Client constructor. Sometimes the location element in the WSDL does not match the URI on the server.

 client = Client(url, location=url) 
+3
source

If you are not hooked using Suds, you should try the Python library we already worked to connect to SugarCRM using Python. It goes through REST compared to SOAP, which should make access much faster.

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

+1
source

I had the same problem when using the SUDS connection stub. I always got Exception: (404, u'Not Found') Everything else was fine tuned, so I just started to guess and try.

I do not know if certain SOAP servers called this or the fact that I need to set the location manually. The solution was to add the service name to the location URL. Therefore, you need to create several stubs for each individual 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 SUDS should by itself (I think), but it was the only way to overcome this error. Maybe it was caused by the fact that I had to specify the Client.location attribute manually, and therefore SUDS does not change it anymore no matter what service I need to call.

Since it took me a while to find out, I'm sure it helps the poor guy: D

Regards, Michael

+1
source

All Articles