2011-06-27 70 views
4

我试图连接到SugarCRM的SOAP服务(这是什么正确的术语?)使用肥皂水:为什么会出现“异常:(404,u'Not找到')”用肥皂水

from suds.client import Client 

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

但最后一行抛出异常:

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') 
+0

你需要指定端口?即http:// localhost:8080/...或者服务所在的端口 – jpm

+0

不需要它是端口80. – Tshepang

回答

3

尝试传球也争论location=urlClient构造。有时WSDL中的location元素与服务器上的URI不匹配。

client = Client(url, location=url) 
+0

伟大的提示!我加上一些其他的WS(例如Talend Open Studio生成的WS),即使'location = url'是正确的,但是你必须发现端点的正确位置,然后传递给SUDS。 – bluish

1

如果你不喜欢使用Suds,你应该尝试一下我们一直在通过Python连接到SugarCRM的Python库。它覆盖REST与SOAP,这应该使访问速度更快。

瞧瞧吧https://github.com/sugarcrm/python_webservices_library

+0

我只是真的开始了。非常感谢。但是你们还没有销售这个(我期望它[这里](http://developers.sugarcrm.com/opensource)),还是它太不成熟? – Tshepang

+0

这是一个新项目,我希望一个社区能够围绕它建立起来,并帮助它成为一个优秀的图书馆。如果您想帮助参与您的Python专业知识,请告诉我。 – jmertic

1

使用肥皂水连接短,当我有同样的问题。我总是得到Exception: (404, u'Not Found')其他一切都设置好,所以我开始猜测和尝试。

我不知道某些SOAP服务器是否会导致这种情况,或者我需要手动设置位置。解决方案是将服务的名称附加到位置URL。所以,你需要为使用的每个不同的服务创建几个存根,但它的工作原理:

servicename = "TestService"  

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

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

这不是预期的行为,因为SUDS应该对这个本身(我认为),但它得到的唯一选择过去这个错误。也许它是由于我需要手动指定Client.location属性而引起的,因此无论我需要调用什么服务,SUDS都不会再更改它。

由于我花了一段时间才能找到答案,我敢肯定,这可以帮助一些可怜的家伙:d

问候, 迈克尔