UnboundLocalError: local variable 'connector' referenced before assignment

UnboundLocalError: local variable 'connector' referenced before assignment

我有一个错误:UnboundLocalError:赋值前引用了局部变量 'connector'。自托管等。我在 init 中有声明。

class OdooUtility():
  connector = None
  driver = None

  def get_control(self):        
    try:
        connector= ODOO(self.host, port=self.port)
        connector.login(self.dbname, self.username, self.password)
    except Exception as e:
        print e.message

    control = connector.env['rm.control']
    control_ids = control.search([])
    c = control.browse(control_ids)
    res = []
    for row in c:
        res.append(row)
    return res

我该如何解决这个问题?感谢您的帮助!

您需要写 self.connectorOdooUtility.connector 而不是 connector。我怀疑 self.connector 是你想要的。