TypeError: object of type 'bool' has no len() - Odoo v9
TypeError: object of type 'bool' has no len() - Odoo v9
我正在尝试通过 Odoov9 模块连接到网络服务。
这是我的 class:
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'
但是每次解析连接服务器的代码时,都会抛出这个错误:
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))
我搜了一下SO,好像跟括号有关,但我还是不太确定。
对此有什么想法吗?
提前致谢!
编辑
这是设置它的代码:
sii_xml_request = fields.Text(
string='SII XML Request',
copy=False,
)
当您尝试访问self.sii_xml_request.时,首先检查它的值是否为空。
在您的例子中,它 returns 是一个空字符串,即 False。为避免这种情况,请尝试以下代码:
_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'.
中没有值,您当然可以更改它以记录您想要显示的不同内容
我正在尝试通过 Odoov9 模块连接到网络服务。
这是我的 class:
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'
但是每次解析连接服务器的代码时,都会抛出这个错误:
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))
我搜了一下SO,好像跟括号有关,但我还是不太确定。
对此有什么想法吗?
提前致谢!
编辑
这是设置它的代码:
sii_xml_request = fields.Text(
string='SII XML Request',
copy=False,
)
当您尝试访问self.sii_xml_request.时,首先检查它的值是否为空。
在您的例子中,它 returns 是一个空字符串,即 False。为避免这种情况,请尝试以下代码:
_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'.
中没有值,您当然可以更改它以记录您想要显示的不同内容