2011-06-27 50 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

問候, 邁克爾