为什么我收到“异常:(404,u“未找到”)”含肥皂水

发布于 2024-11-17 13:35:44 字数 1697 浏览 3 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寂寞美少年 2024-11-24 13:35:44

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

client = Client(url, location=url)

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)
以往的大感动 2024-11-24 13:35:44

我在使用 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)

这不是预期的行为,因为 SUDS 应该自行实现此目的(我认为),但它是克服此错误的唯一选择。也许是因为我需要手动指定 Client.location 属性,因此无论我需要调用什么服务,SUDS 都不会再更改它。

因为我花了一段时间才找到答案,我打赌这会帮助一些可怜的人:D

问候,
迈克尔

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

黎歌 2024-11-24 13:35:44

如果您不喜欢使用 Suds,您应该尝试我们一直致力于通过 Python 连接到 SugarCRM 的 Python 库。它讨论了 REST 与 SOAP,这应该会使访问速度更快。

请访问 https://github.com/sugarcrm/python_webservices_library

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文