TypeError:类型为'bool'的对象没有len()-Odoo v9 [英] TypeError: object of type 'bool' has no len() - Odoo v9

查看:246
本文介绍了TypeError:类型为'bool'的对象没有len()-Odoo v9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过Odoov9模块连接到Web服务.

I'm trying to connect to a webservice through an Odoov9 module.

这是我的课程:

class invoice(models.Model):
_inherit = "account.invoice"

@api.multi
def send_xml_file(self):
    # haciendolo para efacturadelsur solamente por ahora
    host = 'https://www.efacturadelsur.cl'
    post = '/ws/DTE.asmx' # HTTP/1.1
    url = host + post
    _logger.info('URL to be used %s' % url)
    # client = Client(url)
    # _logger.info(client)
    _logger.info('len (como viene): %s' % len(self.sii_xml_request))

    response = pool.urlopen('POST', url, headers={
        'Content-Type': 'application/soap+xml',
        'charset': 'utf-8',
        'Content-Length': len(
            self.sii_xml_request)}, body=self.sii_xml_request)

    _logger.info(response.status)
    _logger.info(response.data)
    self.sii_xml_response = response.data
    self.sii_result = 'Enviado'

但是每次它解析代码以连接到服务器时,都会引发此错误:

But everytime it parses the code to connect to the server, it throws this error:

Odoo Server Error

Traceback (most recent call last):
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 646, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 683, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 319, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 312, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 962, in __call__
return self.method(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 512, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/web/controllers/main.py", line 901, in call_button
action = self._call_kw(model, method, args, {})
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/web/controllers/main.py", line 889, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/api.py", line 381, in old_api
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/l10n_cl_dte/models/invoice.py", line 102, in send_xml_file
_logger.info('len (como viene): %s' % len(self.sii_xml_request))
TypeError: object of type 'bool' has no len()

错误在此行上

_logger.info('URL to be used %s' % url) # client = Client(url) # _logger.info(client) _logger.info('len (como viene): %s' % len(self.sii_xml_request))

_logger.info('URL to be used %s' % url) # client = Client(url) # _logger.info(client) _logger.info('len (como viene): %s' % len(self.sii_xml_request))

我已经搜索过SO,它似乎与括号有关,但是我仍然不确定.

I've searched through SO, and it seems to be related to parenthesis, but I'm still not really sure.

对此有何想法?

提前谢谢!

编辑

这是设置它的代码:

    sii_xml_request = fields.Text(
    string='SII XML Request',
    copy=False,
    )

推荐答案

当您尝试访问 self.sii_xml_request时.首先检查其值是否为空.

When you try to access self.sii_xml_request. First check whether it's value is empty or not.

在您的情况下,它将返回一个空字符串,该字符串为 False .为避免这种情况,请尝试以下代码:

In your case, it returns an empty string which is False. To avoid this, try the following code:

_logger.info('len (como viene): %s' % (len(self.sii_xml_request) if self.sii_xml_request else '')

这将仅记录其中包含值的"self.sii_xml_request".否则,它将只记录一个空字符串.您当然可以更改此设置,以记录一些其他您想显示的东西,如果"self.sii_xml_request"中没有值.

This will only log 'self.sii_xml_request' if it has a value in it. Otherwise it will just log an empty string. You can change this of course to log something different that you would like to show if there is no value in 'self.sii_xml_request'.

这篇关于TypeError:类型为'bool'的对象没有len()-Odoo v9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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