suds.TypeNotFound:找不到类型:'MerchantCode' [英] suds.TypeNotFound: Type not found: 'MerchantCode'

查看:211
本文介绍了suds.TypeNotFound:找不到类型:'MerchantCode'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django开发一个Web,它处理wsdl。我有一个例子代码来处理它,但它写在PHP上,我想把它转换为python为我的django。
这里是PHP文件...

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

$ WSDL =DirectConnect.test.WSDL;

$ 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 =development@yespayments.com.ph;
$ ClientIPAddress = $ _SERVER [REMOTE_ADDR];
$ Notes =这是一个测试。

$ 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:。 $响应 - > OnlineTransactionResult->的TransactionID;
print< br /> TransactionType:。 $响应 - > OnlineTransactionResult-> TRANSACTIONTYPE;
print< br /> MerchantReference:。 $响应 - > OnlineTransactionResult-> MerchantReference;
print< br /> ResponseCode:。 $响应 - > OnlineTransactionResult-> ResponseCode;
print< br /> ResponseShortDescription:。 $响应 - > OnlineTransactionResult-> ResponseShortDescription;
print< br /> ResponseDescription:。 $响应 - > OnlineTransactionResult-> ResponseDescription;
print< br /> TimeStamp:。 $响应 - > OnlineTransactionResult->时间戳;
print< br /> CardID:。 $响应 - > OnlineTransactionResult-> CardData-> CardId中;
print< br /> CardSuffix:。 $响应 - > OnlineTransactionResult-> CardData-> CardSuffix;
print< br /> ExpiryYear:。 $响应 - > OnlineTransactionResult-> CardData-> ExpiryYear;
print< br /> ExpiryMonth:。 $响应 - > OnlineTransactionResult-> CardData-> ExpiryMonth;
print< br /> BINCountryCode:。 $响应 - > OnlineTransactionResult-> BINCountryCode;
print< br /> IPCountryCode:。 $响应 - > OnlineTransactionResult-> IPCountryCode;
print< br /> WarningArray:。 $响应 - > OnlineTransactionResult-> WarningArray;

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

print< br />< br />请求:< br />。用htmlspecialchars($ SoapClient-> __ getLastRequest());
print< br />< br />响应:< 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),

(CardSecurityCode,400),
(CustomerAccountNumber,),
(BillNumber,0),
(CardHolderEmail ,development@yespayments.com.ph),
(ClientIPAddress,http://127.0.0.1:8000/),
(不es,这是测试),
])

response = client.service.OnlineTransaction(values)

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

 追溯(最近的最后一次呼叫):
文件yes_test.py,第24行,在< module>
response = client.service.OnlineTransaction(values)
文件/usr/local/lib/python2.7/dist-packages/suds/client.py,第542行,__call__
return client.invoke(args,kwargs)
文件/usr/local/lib/python2.7/dist-packages/suds/client.py,第595行,调用
soapenv = binding .get_message(self.method,args,kwargs)
文件/usr/local/lib/python2.7/dist-packages/suds/bindings/binding.py,第120行,get_message
content = self.bodycontent(method,args,kwargs)
文件/usr/local/lib/python2.7/dist-packages/suds/bindings/document.py,第63行,bodycontent
p = self.mkparam(method,pd,value)
文件/usr/local/lib/python2.7/dist-packages/suds/bindings/document.py,第105行,mkparam
return Binding.mkparam(self,method,pdef,object)
文件/usr/local/lib/python2.7/dist-packages/suds/bindings/binding.py,第287行,mkparam
return marshaller.process(content)
文件/ usr / local / lib / pytho n2.7 / dist-packages / suds / mx / core.py,第62行,进程
self.append(文档,内容)
文件/usr/local/lib/python2.7 /dist-packages/suds/mx/core.py,第75行,附加
self.appender.append(parent,content)
文件/usr/local/lib/python2.7/ dist-packages / suds / mx / appender.py,第102行,附加
appender.append(parent,content)
文件/usr/local/lib/python2.7/dist-packages /suds/mx/appender.py,第243行,附加
Appender.append(self,child,cont)
文件/usr/local/lib/python2.7/dist-packages/ suds / mx / appender.py,第182行,附加
self.marshaller.append(parent,content)
文件/usr/local/lib/python2.7/dist-packages/suds /mx/core.py,第74行,附加
如果self.start(content):
文件/usr/local/lib/python2.7/dist-packages/suds/mx/ literal.py,第87行,起始
raise TypeNotFound(content.tag)
suds.TypeNotFound:找不到类型:'MerchantCode'

它指出错误在我的python的这一行,

  response = client.service.OnlineTransaction(values)
任何人都可以给我一个关于我的情况的想法?



提前感谢...

解决方案

你确定你的DirectConnect.test.WSDL是正确的吗?这似乎不是请张贴在这里。



添加:



我得到它的工作。请看看结果。这是工作代码(chmod + x main.py来运行它)。

 (sudstest)mike-imac:sudstest mike $ ./main.py 
(OnlineResponse){
TransactionID = 0
TransactionType = 20
MerchantReference =无
ResponseCode =ERMERC
ResponseShortDescription =YESDEC
ResponseDescription =无效商家代码
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' ,
'CardHolderName':'RAUL O REVECHE',
'CardNumber':4005550000000001,
'ExpiryMonth':5,
'ExpiryYear':2013,
' CardID':0,
'CardSecurityCode':400,
'CustomerAccountNumber':'',
'BillNumber':0,
'CardHolderEmail':'development@yespayments.com .ph',
'ClientIPAddress':'http://127.0.0.1:8000/',
'注意':'这是测试',
}

result = client.service.OnlineTransaction(** data)
打印结果

如果__name__ =='__main__':
test_api()


I am developing a web using django and it deals with wsdl. I have an example code in dealing with it but its written on PHP and I wanted to convert it to python for my django. here is the PHP file ...

<?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       = "development@yespayments.com.ph";
  $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());

?>

and this is what i have done to converting it to 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","development@yespayments.com.ph"),
            ("ClientIPAddress","http://127.0.0.1:8000/"),
            ("Notes","This is test"),
            ])

response = client.service.OnlineTransaction(values)

but when i run it, i got this error...

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'

i think that the error is in these line of my python,

response = client.service.OnlineTransaction(values)

can anyone can give me an idea about my situation?

thanks in advance ...

解决方案

Are you sure your DirectConnect.test.WSDL is correct? It seems it's not. Please post it here.

Added:

I got it working. Please have a look at the result. Here is the working code (chmod +x main.py to run it).

(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': 'development@yespayments.com.ph',
        'ClientIPAddress': 'http://127.0.0.1:8000/',
        'Notes': 'This is test',
    }

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

if __name__ == '__main__':
    test_api()

这篇关于suds.TypeNotFound:找不到类型:'MerchantCode'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆