2

我有这个代码:

yestest.py

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

WSDL = 'DirectConnect.production.wsdl'

def test_api():
    url = 'file://' + os.path.join(os.path.abspath(os.path.dirname(__file__)), WSDL)
    print url
    client = abo('file:///home/agileone/workspace/surebooked/surebooked/DirectConnect.production.wsdl')

    data = {
        'MerchantCode': 'HELLOWORLD',
        'MerchantReference':  '3252',
        'TransactionType': 20,
        'Amount': 10,
        '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/',
        'Notes': 'This is test',
    }

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


if __name__ == '__main__':
    test_api()

当我使用它运行它时它运行正常,python payment.py 但是如果我在我的 django 中使用它运行它python manage.py shell

我有一个错误。

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from surebooked.yestest import *
>>> test_api()
file:///home/agileone/workspace/surebooked/surebooked/DirectConnect.production.wsdl
{'ExpiryYear': 2013, 'CardNumber': 4005550000000001L, 'BillNumber': 0, 'CardHolderEmail': 'development@yespayments.com.ph', 'MerchantReference': '3252', 'CurrencyCode': 'USD', 'CardHolderName': 'RAUL O REVECHE', 'ExpiryMonth': 5, 'CustomerAccountNumber': '', 'Amount': 10, 'MerchantCode': 'SUREBOOKED', 'ClientIPAddress': 'http://127.0.0.1/', 'CardID': 0, 'Notes': 'This is test', 'CardSecurityCode': 400, 'TransactionType': 20}
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/agileone/workspace/surebooked/surebooked/../surebooked/yestest.py", line 32, in test_api
    result = client.service.OnlineTransaction(**data)
  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 73, in append
    log.debug('appending parent:\n%s\ncontent:\n%s', parent, content)
  File "/usr/lib/python2.7/logging/__init__.py", line 1120, in debug
    self._log(DEBUG, msg, args, **kwargs)
  File "/usr/lib/python2.7/logging/__init__.py", line 1250, in _log
    self.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1260, in handle
    self.callHandlers(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1300, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 744, in handle
    self.emit(record)
  File "/home/agileone/workspace/surebooked/surebooked/.ve/src/django-debug-toolbar/debug_toolbar/panels/logger.py", line 51, in emit
    'message': record.getMessage(),
  File "/usr/lib/python2.7/logging/__init__.py", line 328, in getMessage
    msg = msg % self.args
  File "/usr/local/lib/python2.7/dist-packages/suds/sax/document.py", line 58, in __str__
    return unicode(self).encode('utf-8')
  File "/usr/local/lib/python2.7/dist-packages/suds/sax/document.py", line 61, in __unicode__
    return self.str()
  File "/usr/local/lib/python2.7/dist-packages/suds/sax/document.py", line 48, in str
    s.append(self.root().str())
AttributeError: 'NoneType' object has no attribute 'str'

我认为问题出在泡沫中,但我不知道如何解决这个问题。

任何人都可以帮助我处理我的情况吗?

我尝试在网上搜索但我找不到任何答案..

提前致谢...

这就是我所做的?这是对的吗?

>>> import pdb; pdb.pm()
> /usr/local/lib/python2.7/dist-packages/suds/sax/document.py(48)str()
-> s.append(self.root().str())
(Pdb) api_test()
*** NameError: name 'api_test' is not defined
(Pdb) from surebooked.yestest import *
(Pdb) api_test()
*** NameError: name 'api_test' is not defined
(Pdb) from surebooked.yestest import *
(Pdb) test_api()
file:///home/agileone/workspace/surebooked/surebooked/DirectConnect.production.wsdl
{'ExpiryYear': 2013, 'CardNumber': 4005550000000001L, 'BillNumber': 0, 'CardHolderEmail': 'development@yespayments.com.ph', 'MerchantReference': '3252', 'last_traceback': '', 'CurrencyCode': 'USD', 'CardHolderName': 'RAUL O REVECHE', 'ExpiryMonth': 5, 'CustomerAccountNumber': '', 'Amount': 10, 'MerchantCode': 'SUREBOOKED', 'ClientIPAddress': 'http://127.0.0.1/', 'CardID': 0, 'Notes': 'This is test', 'CardSecurityCode': 400, 'TransactionType': 20}
*** AttributeError: 'NoneType' object has no attribute 'str'
(Pdb) 
4

3 回答 3

6

您好,您同时使用 DJDt 吗?这是 suds 中的一个错误,当您将其与 Django 调试工具栏一起使用时会引发该错误。检查这个补丁:https ://github.com/bradleyayers/suds-htj 。

于 2012-06-08T08:46:08.960 回答
3

该错误意味着它所说的: NoneType 没有 str 方法,您也不希望它有。

查看堆栈跟踪中的最后一行:s.append(self.root().str()). 它在str召唤self.root();随之而来的self.root()是回归None

您应该做的是从控制台触发测试(或等效代码),并在发生异常时执行import pdb; pdb.pm(). 这将在异常发生(或被处理)时带您进入调试器。从那里,您可以找到None.

于 2012-04-09T09:13:22.223 回答
0

使函数test_api返回result.ResponseDescription而不是仅仅打印它

于 2012-04-09T09:15:50.423 回答