【问题标题】:Make soap client python with suds使用 suds 制作肥皂客户端 python
【发布时间】:2014-07-10 13:00:42
【问题描述】:

我在 perl 中创建了这个脚本:

#!"c:\strawberry\perl\bin\perl.exe"

use strict;

use LWP::UserAgent;
use HTTP::Request;

my $message = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <AddUser xmlns="http://tempuri.org/">
      <HostUserName>hcadmin</HostUserName>
      <HostPassword>XXXXXXXXX</HostPassword>
      <OwnerName>hcadmin</OwnerName>
      <PlanName>Unlimited Plan - Windows</PlanName>
      <NewUserName>froyland</NewUserName>
      <NewUserPassword>XXXXXXX</NewUserPassword>
      <EmailAddress>john@hosting.net</EmailAddress>
      <ResellerType>Dedicated</ResellerType>
      </AddUser>
  </soap:Body>
</soap:Envelope>';
my $userAgent = LWP::UserAgent->new();
my $request = HTTP::Request->new(POST => 'http://painel.a.nrserver.net:8080/UserManager.asmx');
$request->header(SOAPAction => '"http://tempuri.org/AddUser"');
$request->content($message);
$request->content_type("text/xml; charset=utf-8");
my $response = $userAgent->request($request);

if($response->code == 200) {
    print $response->as_string, '\n';
}
else {
    print $response->error_as_HTML;
}

现在我打算在python中做同样的事情,我看了一些组件并找到了suds,但是无法编写像perl这样简单的东西,还没有太多的python经验,你能帮帮我吗?

【问题讨论】:

  • 你用 Python 和 suds 尝试过 anything 吗?向我们展示代码!
  • 你知道,它可能是一行代码。也许你应该read the docs诉诸 SO。 也许

标签: python soap client suds


【解决方案1】:

我用 suds 和 pysimplesoap 创建了示例脚本,但它们并没有像我想要的那样工作,所以我使用 urllib2 做了一些东西,它工作得很好。我有问题,因为我的 API 的 url 是 http://xxxxxx.com:8080/action.asmx 并且 httplib 不起作用。

还是谢谢你的回答。

【讨论】:

    猜你喜欢
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 2013-04-03
    • 2017-07-04
    相关资源
    最近更新 更多