SyntaxError:语法无效 - python 2.7 - Odoo v9社区

时间:2016-09-13 19:53:34

标签: python logging openerp odoo-9

我有这个代码检查是否有指定的提供程序和pem密钥,以便通过xml发送到服务器:

 @api.multi
def send_xml_file(self, envio_dte=None, file_name="envio",company_id=False):
    if not company_id.dte_service_provider:
        raise UserError(_("Not Service provider selected!"))
    try:
        signature_d = self.get_digital_signature_pem(
            company_id)
        seed = self.get_seed(company_id)
        template_string = self.create_template_seed(seed)
        seed_firmado = self.sign_seed(
            template_string, signature_d['priv_key'],
            signature_d['cert'])
        token = self.get_token(seed_firmado,company_id)
    _logger.info(_("Token is: {}").format(token))
    except:
        raise Warning(connection_status[response.e])
        return {'sii_result': 'NoEnviado'}

在这一行:_logger.info(_("Token is: {}").format(token))正在向我招募SyntaxError: invalid syntax这是我的追溯:

Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoov9/lib/python2.7/site-packages/werkzeug/serving.py", line 177, in run_wsgi
execute(self.server.app)
File "/home/kristian/.virtualenvs/odoov9/lib/python2.7/site-packages/werkzeug/serving.py", line 165, in execute
application_iter = app(environ, start_response)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/service/server.py", line 246, in app
return self.app(e, s)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/service/wsgi_server.py", line 184, in application
return application_unproxied(environ, start_response)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/service/wsgi_server.py", line 170, in application_unproxied
result = handler(environ, start_response)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 1492, in __call__
self.load_addons()
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 1513, in load_addons
m = __import__('openerp.addons.' + module)
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/modules/module.py", line 61, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/home/kristian/odoov9/solti/l10n_cl_dte/__init__.py", line 2, in <module>
from . import models, controllers, wizard
File "/home/kristian/odoov9/solti/l10n_cl_dte/models/__init__.py", line 2, in <module>
from . import invoice, partner, company, payment_term, sii_regional_offices
File "/home/kristian/odoov9/solti/l10n_cl_dte/models/invoice.py", line 500
_logger.info(_("Token is: {}").format(token))
      ^
SyntaxError: invalid syntax

我已经检查了缺失的括号,以及类似的东西,但我仍然无法弄明白。

有关于此的任何想法吗?

提前致谢!

1 个答案:

答案 0 :(得分:1)

需要将记录器标记在try块中。

@api.multi
def send_xml_file(self, envio_dte=None, file_name="envio",company_id=False):
    if not company_id.dte_service_provider:
        raise UserError(_("Not Service provider selected!"))
    try:
        signature_d = self.get_digital_signature_pem(
            company_id)
        seed = self.get_seed(company_id)
        template_string = self.create_template_seed(seed)
        seed_firmado = self.sign_seed(
            template_string, signature_d['priv_key'],
            signature_d['cert'])
        token = self.get_token(seed_firmado,company_id)
        _logger.info(_("Token is: {}").format(token))
    except:
        # This is probably not doing what you expect
        # raise will stop program execution, so the 
        # return will not actually return.
        raise Warning(connection_status[response.e])
        return {'sii_result': 'NoEnviado'}