AttributeError:'NoneType'对象在suds中没有属性'str' [英] AttributeError: 'NoneType' object has no attribute 'str' in suds

查看:154
本文介绍了AttributeError:'NoneType'对象在suds中没有属性'str'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们的项目中使用了suds客户端的WSDL。



我有这个代码。

  sudsclient = sudsClient(settings.WSDL_URL)
values = {
MerchantCode:settings.YP_MERCHANT_CODE ,
MerchantReference:str(reference_id),
TransactionType:settings.YP_TRANSACTION_TYPE,
金额:int(充电),
CurrencyCode:client.currency ,
CardHolderName:str(form.cleaned_data ['name_on_card']),
CardNumber:str(form.cleaned_data ['card_number']),
ExpiryMonth (form.cleaned_data ['exp_month']),
ExpiryYear:int(form.cleaned_data ['exp_year']),
CardID:0,
CardSecurityCode (form.cleaned_da ta ['security_code']),
CustomerAccountNumber:,
BillNumber:0,
CardHolderEmail:str(form.cleaned_data ['email']),
ClientIPAddress:get_ip,
Notes:OK,
}
response = sudsclient.service.OnlineTransaction(** values)

当我运行我的程序,我收到这个错误:

 code>异常类型:AttributeError 
异常值:
'NoneType'对象没有属性'str'
异常位置:/usr/local/lib/python2.7/dist- package / suds / sax / document.py str,第48行

我确定我的代码我的本地和测试是一样的。



我认为问题出现在 suds 中,但我并不了解如何解决它



有人可以帮助我吗?
感谢提前..

 环境:

请求方法:GET
请求URL:http://127.0.0.1:8000/1/book/save/?csrfmiddlewaretoken=05e5bdb542c3be7515b87e8160c347a0&check_in=2012-04-24&check_out=2012-04-25&no_of_nights=1&quantity=1&product = 4和;价格= 900.0&安培; chargedMasterCard = 180.0&安培; chargedVisa = 90.0&安培; totalcostMasterCard = 720.0&安培; totalcostVisa = 810.0&安培; TOTALCOST = 900.0&安培;带电= 10.0&安培; price_rate = 1000.0&安培; old_totalcost = 1000.0&安培; discount_charged = 100.0&安培;如first_name = dsnmbmh&安培;姓氏= jhbjhb&安培;电子邮件= jdlabandero%40agile.com.ph&安培;接触= 657879&安培;地址= gjkj&安培; no_of_adult = 1&安培; no_of_kid = 0&安培;备忘录=安培; CARD_TYPE =万事达&安培; CARD_NUMBER = 40000234234210&安培; security_code = 788& name_on_card = ghjk& exp_month = 1& exp_year = 2012

Django版本:1.3.1
Python版本:2.7.1
安装的应用程序:
[ 'admin_tools',
'admin_tools.theming',
'admin_tools.menu ,
'admin_tools.dashboard',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sh',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
' django.contrib.admin',
'surebooked.booking',
'surebooked.api',
'surebooked.account_app',
'surebooked.client_app',
'surebooked.product_app',
'surebooked.report_app',
'debug_toolbar',
'billing',
'south',
'paypal.standard。 ipn',
'django_extensions',
'cms',
'menus',
'mptt',
'south',
'cms。 plugins.text',
'cms.plugins.picture',
'cms.plugins.link',
'cms.plugins.file',
'cms.plugins。片段,
'cms.plugins.googlemap',
'sekizai',
'django.contrib.admin',
'filer' ,
'sorl.thumbnail',
'easy_thumbnails',
'cmsplugin_filer_file',
'cmsplugin_filer_folder',
'cmsplugin_filer_image',
'cmsplugin_filer_teaser' ,
'cmsplugin_filer_video',
'media_tree',
'django_cron']
安装的中间件:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django。 contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'media_tree.middleware.SessionPostMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware')


追溯:
文件/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.pyin get_response
111. response = callback(request,* callback_args,** callback_kwargs)
文件/home/agileone/workspace/surebooked/surebooked/../surebooked/booking/views.pyin booking_save_page
752. response = sudsclient.service.OnlineTransaction(** values)
__call__中的文件/usr/local/lib/python2.7/dist-packages/suds/client.py
542. 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.pyin get_message
120. content = self.bodycontent(method,args,kwargs)
文件/ usr / local / lib /python2.7/dist-packages/suds/bindings/document.pyin bodycontent
63。 p = self.mkparam(method,pd,value)
文件/usr/local/lib/python2.7/dist-packages/suds/bindings/document.py在mkparam
105.返回Binding.mkparam(self,method,pdef,object)
文件/usr/local/lib/python2.7/dist-packages/suds/bindings/binding.py在mkparam
287.返回marshaller.process(content)
进程
中的文件/usr/local/lib/python2.7/dist-packages/suds/mx/core.py62. self.append(文档,内容)
附加文件/usr/local/lib/python2.7/dist-packages/suds/mx/core.py
73. log.debug('appending parent:\\\
% s\\\
content:\\\
%s',parent,content)
文件/usr/lib/python2.7/logging/__init__.py在debug
1120. self._log(DEBUG文件/usr/lib/python2.7/logging/__init__.py在_log
1250. self.handle(record)
文件 /usr/lib/python2.7/logging/__init__.py在手le
1260. self.callHandlers(record)
callHandlers中的/usr/lib/python2.7/logging/__init__.py文件
1300. hdlr.handle(record)
文件/usr/lib/python2.7/logging/__init__.py处理
744. self.emit(record)
文件/ home / agileone / workspace / surebooked / surebooked / .ve / src / django-debug-toolbar / debug_toolbar / panels / logger.pyin emit
51.'message':record.getMessage(),
文件/ usr / lib / python2。 7 / logging / __ init__.pyin getMessage
328. msg = msg%self.args
文件/usr/local/lib/python2.7/dist-packages/suds/sax/document。 pyin __str__
58. return unicode(self).encode('utf-8')
文件/usr/local/lib/python2.7/dist-packages/suds/sax/document .pyin __unicode__
61. return self.str()
文件/usr/local/lib/python2.7/dist-packages/suds/sax/document.py在str $ b中$ b 48。 s.append(self.root()。str())

异常类型:/ 1 / book / save /
中的AttributeError异常值:'NoneType'对象没有属性'str '

我真的不知道为什么我有这个错误。
现在我在本地和我的制作中都有同样的错误。
btw,当我分离代码并尝试运行。它运行正常。



sudstest.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(url)

data = {
'MerchantCode':'HELLO',
'MerchantReference':'3252',
'TransactionType' 20,
'金额':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:8000/ ',
'Notes':'这是测试',
}

打印数据
result = client.service.OnlineTransaction(** data)
print result.ResponseDescription


解决方案

异常是由没有值由self.root返回,如suds.sax.Document中所示,

  def root(self):
如果len(self.children):
return self.children [0]
else:
return无

所以这似乎是由于缺少一些数据字段造成的。再次在本地计算机上重播您在测试服务器上填写的确切数据,可能会有所帮助。还要检查测试服务器上的Django设置,以确保它们与本地设置相似。


I am using suds client for WSDL in our project.

i have this code .

sudsclient = sudsClient(settings.WSDL_URL)
values = {
                                    "MerchantCode": settings.YP_MERCHANT_CODE,
                                    "MerchantReference": str(reference_id),
                                    "TransactionType":settings.YP_TRANSACTION_TYPE,
                                    "Amount":int(charged),
                                    "CurrencyCode":client.currency,
                                    "CardHolderName":str(form.cleaned_data['name_on_card']),
                                    "CardNumber": str(form.cleaned_data['card_number']),
                                    "ExpiryMonth":int(form.cleaned_data['exp_month']),
                                    "ExpiryYear":int(form.cleaned_data['exp_year']),
                                    "CardID":0,
                                    "CardSecurityCode":str(form.cleaned_data['security_code']),
                                    "CustomerAccountNumber":"",
                                    "BillNumber":0,
                                    "CardHolderEmail":str(form.cleaned_data['email']),
                                    "ClientIPAddress":get_ip,
                                    "Notes":"OK",
                                            }
response = sudsclient.service.OnlineTransaction(**values)

when i run my program i got this error:

Exception Type: AttributeError
Exception Value:    
'NoneType' object has no attribute 'str'
Exception Location: /usr/local/lib/python2.7/dist-packages/suds/sax/document.py in str, line 48

I am sure that my code in my local and test are same.

I think the problem is in the suds, but i don't have any idea on how to solve it.

Do anyone can help me in my case? thanks in advance ..

 Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/1/book/save/?csrfmiddlewaretoken=05e5bdb542c3be7515b87e8160c347a0&check_in=2012-04-24&check_out=2012-04-25&no_of_nights=1&quantity=1&product=4&price=900.0&chargedMasterCard=180.0&chargedVisa=90.0&totalcostMasterCard=720.0&totalcostVisa=810.0&totalcost=900.0&charged=10.0&price_rate=1000.0&old_totalcost=1000.0&discount_charged=100.0&first_name=dsnmbmh&last_name=jhbjhb&email=jdlabandero%40agile.com.ph&contact=657879&address=gjkj&no_of_adult=1&no_of_kid=0&memo=&card_type=MasterCard&card_number=40000234234210&security_code=788&name_on_card=ghjk&exp_month=1&exp_year=2012

Django Version: 1.3.1
Python Version: 2.7.1
Installed Applications:
['admin_tools',
 'admin_tools.theming',
 'admin_tools.menu',
 'admin_tools.dashboard',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'django.contrib.admin',
 'surebooked.booking',
 'surebooked.api',
 'surebooked.account_app',
 'surebooked.client_app',
 'surebooked.product_app',
 'surebooked.report_app',
 'debug_toolbar',
 'billing',
 'south',
 'paypal.standard.ipn',
 'django_extensions',
 'cms',
 'menus',
 'mptt',
 'south',
 'cms.plugins.text',
 'cms.plugins.picture',
 'cms.plugins.link',
 'cms.plugins.file',
 'cms.plugins.snippet',
 'cms.plugins.googlemap',
 'sekizai',
 'django.contrib.admin',
 'filer',
 'sorl.thumbnail',
 'easy_thumbnails',
 'cmsplugin_filer_file',
 'cmsplugin_filer_folder',
 'cmsplugin_filer_image',
 'cmsplugin_filer_teaser',
 'cmsplugin_filer_video',
 'media_tree',
 'django_cron']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.csrf.CsrfResponseMiddleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware',
 'media_tree.middleware.SessionPostMiddleware',
 'cms.middleware.page.CurrentPageMiddleware',
 'cms.middleware.user.CurrentUserMiddleware',
 'cms.middleware.toolbar.ToolbarMiddleware')


    Traceback:
    File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
      111.                         response = callback(request, *callback_args, **callback_kwargs)
    File "/home/agileone/workspace/surebooked/surebooked/../surebooked/booking/views.py" in booking_save_page
      752.                             response = sudsclient.service.OnlineTransaction(**values)
    File "/usr/local/lib/python2.7/dist-packages/suds/client.py" in __call__
      542.             return client.invoke(args, kwargs)
    File "/usr/local/lib/python2.7/dist-packages/suds/client.py" in invoke
      595.         soapenv = binding.get_message(self.method, args, kwargs)
    File "/usr/local/lib/python2.7/dist-packages/suds/bindings/binding.py" in get_message
      120.         content = self.bodycontent(method, args, kwargs)
    File "/usr/local/lib/python2.7/dist-packages/suds/bindings/document.py" in bodycontent
      63.             p = self.mkparam(method, pd, value)
    File "/usr/local/lib/python2.7/dist-packages/suds/bindings/document.py" in mkparam
      105.             return Binding.mkparam(self, method, pdef, object)
    File "/usr/local/lib/python2.7/dist-packages/suds/bindings/binding.py" in mkparam
      287.         return marshaller.process(content)
    File "/usr/local/lib/python2.7/dist-packages/suds/mx/core.py" in process
      62.             self.append(document, content)
    File "/usr/local/lib/python2.7/dist-packages/suds/mx/core.py" in append
      73.         log.debug('appending parent:\n%s\ncontent:\n%s', parent, content)
    File "/usr/lib/python2.7/logging/__init__.py" in debug
      1120.             self._log(DEBUG, msg, args, **kwargs)
    File "/usr/lib/python2.7/logging/__init__.py" in _log
      1250.         self.handle(record)
    File "/usr/lib/python2.7/logging/__init__.py" in handle
      1260.             self.callHandlers(record)
    File "/usr/lib/python2.7/logging/__init__.py" in callHandlers
      1300.                     hdlr.handle(record)
    File "/usr/lib/python2.7/logging/__init__.py" in handle
      744.                 self.emit(record)
    File "/home/agileone/workspace/surebooked/surebooked/.ve/src/django-debug-toolbar/debug_toolbar/panels/logger.py" in emit
      51.             'message': record.getMessage(),
    File "/usr/lib/python2.7/logging/__init__.py" in getMessage
      328.             msg = msg % self.args
    File "/usr/local/lib/python2.7/dist-packages/suds/sax/document.py" in __str__
      58.         return unicode(self).encode('utf-8')
    File "/usr/local/lib/python2.7/dist-packages/suds/sax/document.py" in __unicode__
      61.         return self.str()
    File "/usr/local/lib/python2.7/dist-packages/suds/sax/document.py" in str
      48.         s.append(self.root().str())

    Exception Type: AttributeError at /1/book/save/
    Exception Value: 'NoneType' object has no attribute 'str'

i really2x don't know why i got this error. Now I got the same error in my local and my production. btw, when i separate the code and try to run. it runs ok.

sudstest.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(url)

data = {
    'MerchantCode': 'HELLO',
    '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:8000/',
    'Notes': 'This is test',
}

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

解决方案

The Exception is caued by the None value returned by self.root, as following in suds.sax.Document,

def root(self): 
    if len(self.children): 
        return self.children[0] 
    else: 
        return None 

So it seems caused by lacking some data fields. Replay the exact data which you fill on the test server, on local machine again might help. Also check Django settings on the test server to make sure they are similar as your local settings.

这篇关于AttributeError:'NoneType'对象在suds中没有属性'str'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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