python - 'NoneType' 对象在泡沫中没有属性 'str'

标签 python django suds

我有这个代码:

测试.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 运行它时它运行正常 但是如果我使用 python manage.py shell

在我的 django 中运行它

我遇到了一个错误。

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) 

最佳答案

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

关于python - 'NoneType' 对象在泡沫中没有属性 'str',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10071005/

相关文章:

python - Tkinter:root.after(), root.after_cancel()

python - Django rest框架和模型验证

python - 在 python 中调用 SOAP 客户端(suds) 返回错误 AuthenticationError.LOGIN_COOKIE_REQUIRED

python - 如何以高效内存的方式使用 SOAP 水?

python - 使用 PyYAML 在 yaml 中将文档作为原始字符串加载

python - 再次添加数组的每个成员,紧接着其自身

python log2 超过列表列表的索引

sql - 拒绝两个字段中的空值

python - 检查对象是否存在

caching - python 3 suds 缓存不工作