我有这段代码:
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
运行它时运行正常
但如果我使用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)
答案 0 :(得分:6)
嗨,你在同时使用DJDt吗? 当你将它与Django Debug Toolbar一起使用时,它是suds中的一个bug。检查此补丁:https://github.com/bradleyayers/suds-htj。
答案 1 :(得分:3)
错误意味着它的含义:NoneType没有str方法,你也不期望它。
查看堆栈跟踪中的最后一行:s.append(self.root().str())
。它正在str
上调用self.root()
;因此self.root()
正在返回None
。
解决此问题的方法是从控制台触发测试(或等效代码),并在发生异常时import pdb; pdb.pm()
。这将使您在发生异常(或已处理)时进入调试器。从那里,您可以找到None
的来源。
答案 2 :(得分:0)
让功能test_api
返回result.ResponseDescription
而不是仅打印