为什么我用肥皂水得到“Exception:(404,u'Not Found”)

2024-06-16 16:46:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试连接到sugarcrmsoap服务(正确的术语是什么?)使用肥皂水:

from suds.client import Client

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

但最后一行抛出了一个例外:

^{pr2}$

Tags: fromimportclientlocalhosthttpurlsoapsuds
3条回答

如果您不喜欢使用Suds,那么您应该尝试一下我们一直在开发的Python库,以便通过Python连接到SugarCRM。它超过了REST而不是SOAP,这将使访问速度更快。在

https://github.com/sugarcrm/python_webservices_library查看

尝试同时将参数location=url传递给Client构造函数。有时WSDLs中的location元素与服务器上的URI不匹配。在

client = Client(url, location=url)

我在使用SUDS连接存根时也遇到了同样的问题。我总是得到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)

这不是有意的行为,因为肥皂水本身应该这样做(我认为),但这是唯一的选择来克服这个错误。可能是因为我需要手动指定Client.location属性,所以无论我需要调用什么服务,SUDS都不会再更改它。在

因为我花了一段时间才发现,我敢打赌这对一个可怜的家伙有帮助:D

谨致问候, 迈克尔

相关问题 更多 >