suds.TypeNotFound:未找到类型:“MerchantCode”

2023-12-04

我正在使用 django 开发一个网络,它处理 wsdl。我有一个处理它的示例代码,但它是用 PHP 编写的,我想将它转换为 python 以用于我的 django。 这是 PHP 文件...

<?php
  ini_set("soap.wsdl_cache_enabled", "0");

  $WSDL                  = "DirectConnect.test.WSDL";

  $MerchantCode          = "HELLO";
  $MerchantReference     = "" . time();
  $TransactionType       = 20;
  $Amount                = 100;
  $CurrencyCode          = "PHP";
  $CardHolderName        = "RAUL O REVECHE";
  $CardNumber            = "4005550000000001";
  $ExpiryMonth           = 5;
  $ExpiryYear            = 2013;
  $CardID                = 0;
  $CardSecurityCode      = "400";
  $CustomerAccountNumber = "";
  $BillNumber            = 0;
  $CardHolderEmail       = "[email protected]";
  $ClientIPAddress       = $_SERVER["REMOTE_ADDR"];
  $Notes                 = "This is a test.";

  $SoapClient = new SoapClient($WSDL,array(
    "soap_version" => SOAP_1_2,
    "features"     => SOAP_SINGLE_ELEMENT_ARRAYS,
    "cache_wsdl"   => WSDL_CACHE_NONE,
    "trace"        => 1,
    "exceptions"   => 0));

  try
  {
    $response = $SoapClient->OnlineTransaction(array(
      "MerchantCode"          => $MerchantCode,
      "MerchantReference"     => $MerchantReference,
      "TransactionType"       => $TransactionType,
      "Amount"                => $Amount,
      "CurrencyCode"          => $CurrencyCode,
      "CardHolderName"        => $CardHolderName,
      "CardNumber"            => $CardNumber,
      "ExpiryMonth"           => $ExpiryMonth,
      "ExpiryYear"            => $ExpiryYear,
      "CardID"                => $CardID,
      "CardSecurityCode"      => $CardSecurityCode,
      "CustomerAccountNumber" => $CustomerAccountNumber,
      "BillNumber"            => $BillNumber,
      "CardHolderEmail"       => $CardHolderEmail,
      "ClientIPAddress"       => $ClientIPAddress,
      "Notes"                 => $Notes
      ));

    print "<br />TransactionID: ".            $response->OnlineTransactionResult->TransactionID;
    print "<br />TransactionType: ".          $response->OnlineTransactionResult->TransactionType;
    print "<br />MerchantReference: ".        $response->OnlineTransactionResult->MerchantReference;
    print "<br />ResponseCode: ".             $response->OnlineTransactionResult->ResponseCode;
    print "<br />ResponseShortDescription: ". $response->OnlineTransactionResult->ResponseShortDescription;
    print "<br />ResponseDescription: ".      $response->OnlineTransactionResult->ResponseDescription;
    print "<br />TimeStamp: ".                $response->OnlineTransactionResult->TimeStamp;
    print "<br />CardID: ".                   $response->OnlineTransactionResult->CardData->CardID;
    print "<br />CardSuffix: ".               $response->OnlineTransactionResult->CardData->CardSuffix;
    print "<br />ExpiryYear: ".               $response->OnlineTransactionResult->CardData->ExpiryYear;
    print "<br />ExpiryMonth: ".              $response->OnlineTransactionResult->CardData->ExpiryMonth;
    print "<br />BINCountryCode: ".           $response->OnlineTransactionResult->BINCountryCode;
    print "<br />IPCountryCode: ".            $response->OnlineTransactionResult->IPCountryCode;
    print "<br />WarningArray: ".             $response->OnlineTransactionResult->WarningArray;

  }
  catch (SoapFault $exception)
  {
    print $exception;
  }

  print "<br /><br />Request:<br />". htmlspecialchars($SoapClient->__getLastRequest());
  print "<br /><br />Response:<br />". htmlspecialchars($SoapClient->__getLastResponse());

?>

这就是我将其转换为 python 所做的事情......

from suds.client import Client
import collections
url = 'file:///home/myFile/DirectConnect.test.WSDL'
client = Client(url)
values = collections.OrderedDict([
            ("MerchantCode", "HELLO"),
            ("MerchantReference", ""),
            ("TransactionType",20),
            ("Amount",100),
            ("CurrencyCode","PHP"),
            ("CardHolderName","RAUL O REVECHE"),
            ("CardNumber", "4005550000000001"),
            ("ExpiryMonth",5),
            ("ExpiryYear",2013),
            ("CardID",0),
            ("CardSecurityCode","400"),
            ("CustomerAccountNumber",""),
            ("BillNumber",0),
            ("CardHolderEmail","[email protected]"),
            ("ClientIPAddress","http://127.0.0.1:8000/"),
            ("Notes","This is test"),
            ])

response = client.service.OnlineTransaction(values)

但是当我运行它时,我收到了这个错误......

Traceback (most recent call last):
  File "yes_test.py", line 24, in <module>
    response = client.service.OnlineTransaction(values)
  File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 542, in __call__
    return client.invoke(args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/suds/client.py", line 595, in invoke
    soapenv = binding.get_message(self.method, args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/suds/bindings/binding.py", line 120, in get_message
    content = self.bodycontent(method, args, kwargs)
  File "/usr/local/lib/python2.7/dist-packages/suds/bindings/document.py", line 63, in bodycontent
    p = self.mkparam(method, pd, value)
  File "/usr/local/lib/python2.7/dist-packages/suds/bindings/document.py", line 105, in mkparam
    return Binding.mkparam(self, method, pdef, object)
  File "/usr/local/lib/python2.7/dist-packages/suds/bindings/binding.py", line 287, in mkparam
    return marshaller.process(content)
  File "/usr/local/lib/python2.7/dist-packages/suds/mx/core.py", line 62, in process
    self.append(document, content)
  File "/usr/local/lib/python2.7/dist-packages/suds/mx/core.py", line 75, in append
    self.appender.append(parent, content)
  File "/usr/local/lib/python2.7/dist-packages/suds/mx/appender.py", line 102, in append
    appender.append(parent, content)
  File "/usr/local/lib/python2.7/dist-packages/suds/mx/appender.py", line 243, in append
    Appender.append(self, child, cont)
  File "/usr/local/lib/python2.7/dist-packages/suds/mx/appender.py", line 182, in append
    self.marshaller.append(parent, content)
  File "/usr/local/lib/python2.7/dist-packages/suds/mx/core.py", line 74, in append
    if self.start(content):
  File "/usr/local/lib/python2.7/dist-packages/suds/mx/literal.py", line 87, in start
    raise TypeNotFound(content.tag)
suds.TypeNotFound: Type not found: 'MerchantCode'

我认为错误出在我的 python 的这些行中,

response = client.service.OnlineTransaction(values)

谁能告诉我我的情况吗?

提前致谢 ...


您确定您的 DirectConnect.test.WSDL 正确吗?看来并非如此。请张贴在这里。

Added:

我成功了。请看一下结果。这是工作代码(chmod +x main.py 运行它)。

(sudstest)mike-imac:sudstest mike$ ./main.py 
(OnlineResponse){
   TransactionID = 0
   TransactionType = 20
   MerchantReference = None
   ResponseCode = "ERMERC"
   ResponseShortDescription = "YESDEC"
   ResponseDescription = "Invalid Merchant Code"
   TimeStamp = "2012/01/24 17:21:37"
   CardData = 
      (YESCardData){
         CardID = 0
         ExpiryYear = 0
         ExpiryMonth = 0
      }
 }

main.py

#!/usr/bin/env python
import os
from suds.client import Client

WSDL = 'DirectConnect.test.WSDL'

def test_api():
    url = 'file://' + os.path.join(os.path.abspath(os.path.dirname(__file__)), WSDL)
    client = Client(url)

    data = {
        'MerchantCode': 'HELLO',
        'MerchantReference':  '',
        'TransactionType': 20,
        'Amount': 100,
        'CurrencyCode': 'USD',
        'CardHolderName': 'RAUL O REVECHE',
        'CardNumber': 4005550000000001,
        'ExpiryMonth': 5,
        'ExpiryYear': 2013,
        'CardID': 0,
        'CardSecurityCode': 400,
        'CustomerAccountNumber': '',
        'BillNumber': 0,
        'CardHolderEmail': '[email protected]',
        'ClientIPAddress': 'http://127.0.0.1:8000/',
        'Notes': 'This is test',
    }

    result = client.service.OnlineTransaction(**data)
    print result

if __name__ == '__main__':
    test_api()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

suds.TypeNotFound:未找到类型:“MerchantCode” 的相关文章

  • 查找与另一列 Pandas 中的唯一值关联的列中的值的交集

    如果我有一个像这样的数据框 非常小的例子 col1 col2 0 a 1 1 a 2 2 b 1 3 b 2 4 b 4 5 c 1 6 c 2 7 c 3 我想要所有的交集col2当价值观与其独特性相关时col1值 因此在这种情况下 交集
  • 在 Linux 上使用多处理时,TKinter 窗口不会出现

    我想生成另一个进程来异步显示错误消息 同时应用程序的其余部分继续 我正在使用multiprocessingPython 2 6 中的模块来创建进程 我试图用以下命令显示窗口TKinter 这段代码在Windows上运行良好 但在Linux上
  • 高级描述熊猫

    有没有像 pandas 那样更高级的功能 通常我会继续这样 r pd DataFrame np random randn 1000 columns A r describe 我会得到一份很好的总结 就像这样 A count 1000 000
  • 如何在Django终端后台启动celery

    我开始芹菜作为 python manage py celeryd 它正在工作 但在前台 然后为了测试命令 我需要启动另一个终端并在那里执行操作 有什么办法可以在后台启动它吗 我试过这个 python manage py celeryd 但话
  • Python-验证我的文档 xls 中是否存在工作表

    我正在尝试在空闲时间设计一个小程序 加载 xls 文件 然后在要扫描的文档中选择一张纸 步骤1 用户导入 xls文件 导入程序后检查文件是否存在 我能做到的 第 2 步 我要求用户提供要分析的文档表 xls 的名称 这就是它停止的地方 该程
  • 使用 file_get_content 发布数据

    我已经做了一些关于如何使用的研究file get content与帖子 我也读过this one https stackoverflow com questions 2445276 how to post data in php using
  • python Recipe:列出最接近等于值的项[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 考虑像这样的列表 0 3 7 10 12 15 19 21 我想获得最接近任何值的最近的最小数字 所以如果我通过4 我会得到3 如果我
  • 是否可以在Python中将日+月(不是年)与当前日+月进行比较?

    我正在获取 5 月 10 日 格式的数据 我试图弄清楚它是今年还是明年 该日期仅一年 因此 5 月 10 日表示 2015 年 5 月 10 日 而 5 月 20 日表示 2014 年 5 月 20 日 为此 我想将字符串转换为日期格式并进
  • Django 独特的不工作

    我在从查询中过滤掉重复项时遇到问题 我正在使用 Django 1 4 和 Postgres 8 4 13 我在我的模型对象上使用这个查询 它是一个 jquery 自动完成 term request GET get term field re
  • 无法导入QUERY_TERMS

    我正在运行一个网站Python and Django Django filters 2 1 installed Django 2 1 installed 当我运行时 我收到以下错误 importError Could not import
  • Django 将 JSON 数据传递给静态 getJSON/Javascript

    我正在尝试从 models py 中获取数据并将其序列化为views py 中的 JSON 对象 模型 py class Platform models Model platformtype models CharField max len
  • 如何创建用于霍夫曼编码和解码的树?

    对于我的作业 我将对霍夫曼树进行编码和解码 我在创建树时遇到问题 并且陷入困境 不要介意打印语句 它们只是让我测试并查看函数运行时的输出是什么 对于第一个 for 循环 我从主块中用于测试的文本文件中获取了所有值和索引 在第二个 for 循
  • 是否可以使用 Anaconda 包作为 Google Cloud Functions 的依赖项?

    我正在使用 Python 运行时编写 Google Cloud Function 我需要包含一些无法使用的依赖项pip 如文档中所述here https cloud google com functions docs writing spe
  • 如何使用 enumerate 来倒数?

    letters a b c 假设这是我的清单 在哪里for i letter in enumerate letters 将会 0 a 1 b 2 c 我怎样才能让它向后枚举 如 2 a 1 b 0 c 这是一个很好的解决方案并且工作完美 i
  • Readfile 从大文件中读取 0 字节?

    我正在尝试通过以下方式发送一个大文件readfile 但是 没有任何内容发送到浏览器 并且readfile 回报0 not false 我尝试发送的文件大小为 4GiB 并且可由 PHP 读取 我正在设置set time limit 0 以
  • 使用 MPI 的 Allreduce 对 Python 对象求和

    我正在使用使用 Python 中的字典和计数器构建的稀疏张量数组操作 我想让并行使用这个数组操作成为可能 最重要的是 我最终在每个节点上都有计数器 我想使用 MPI Allreduce 或另一个不错的解决方案 将其添加在一起 例如 使用计数
  • PHP条件,如果当前页面,则链接突出显示[关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions 我有一个带
  • 通过 Sparkpost 发送 iCal 邀请

    我正在尝试使用 SparkPost 通过电子邮件以附件形式发送日历邀请 但收到电子邮件后邀请不会打开 我使用两个文件 calendarinvite php 来创建邀请 使用 Sendemail php 来发送电子邮件 calendarinv
  • 如何同时接受int和float类型的输入?

    我正在制作一个货币转换器 如何让 python 同时接受整数和浮点数 我就是这样做的 def aud brl amount From to ER 0 42108 if amount int if From strip aud and to
  • 在Python中停止ThreadPool中的进程

    我一直在尝试为控制某些硬件的库编写一个交互式包装器 用于 ipython 有些调用对 IO 的影响很大 因此并行执行任务是有意义的 使用 ThreadPool 几乎 效果很好 from multiprocessing pool import

随机推荐