NeoVe NeoVe - 1 year ago 101
Python Question

TypeError: object of type 'bool' has no len() - Odoo v9

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

This is my class:

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

def send_xml_file(self):
# haciendolo para efacturadelsur solamente por ahora
host = ''
post = '/ws/DTE.asmx' # HTTP/1.1
url = host + post'URL to be used %s' % url)
# client = Client(url)
#'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)
self.sii_xml_response =
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/", line 646, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/", line 683, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/", line 319, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/service/", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/", line 312, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/", line 962, in __call__
return self.method(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/", line 512, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/web/controllers/", line 901, in call_button
action = self._call_kw(model, method, args, {})
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/web/controllers/", line 889, in _call_kw
return getattr(request.registry.get(model), method)(, request.uid, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/", line 381, in old_api
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/l10n_cl_dte/models/", line 102, in send_xml_file'len (como viene): %s' % len(self.sii_xml_request))
TypeError: object of type 'bool' has no len()

The error is on this line'URL to be used %s' % url)
# client = Client(url)
#'len (como viene): %s' % len(self.sii_xml_request))

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

Any ideas on this?

Thanks in advance!


This is the code that sets it:

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

Answer Source

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

In your case, it returns an empty string which is False. To avoid this, try the following code:'len (como viene): %s' % (len(self.sii_xml_request) if self.sii_xml_request else '')

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'.