从查询返回的列表到Tornad中的整数

2024-04-26 08:00:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这些变量:

PERM_READ = 0x01
PERM_WRITE = 0x02
PERM_CMDS = 0x04

以及检查网络或传感器权限的功能。一种确定用户权限的函数。在

这是函数:

^{2}$

例如,当我用这个处理程序调用一个页面时,我遇到了一个错误:

class NetworkStatusHandler(BaseHandler):
# Requires authentication 
@tornado.web.authenticated
def get(self, nid):

    # Retrieve the current user 
    usr = self.get_current_user()
    usr_id = usr['id']

    perm = self.db.query("SELECT n.perm FROM nets_permissions as n \
                          WHERE n.network_id=%s AND n.user_id=%s", nid, int(usr_id))

    # Check whether the user has access to the network 
    perms = self.check_network_access(nid, perm)
    net = self.get_network(nid)
    # Render the networks page
    self.render("networkstatus.html", net=net)

我的错误是:

File "./wsn.py", line 264, in check_network_access
raise tornado.web.HTTPError(403, "access forbidden %s %s", perms['perm'], access)
HTTPError: HTTP 403: Forbidden (access forbidden 4 1)

我认为这是一个问题,在通过龋齿烫发/访问功能。。。我如何传递这个变量,才能做到这是一个整数而不是一个列表?在

谢谢你的帮助!在


Tags: the函数self功能id权限getnet
1条回答
网友
1楼 · 发布于 2024-04-26 08:00:13

这是正确的方法:

class NetworkStatusHandler(BaseHandler):
# Requires authentication 
@tornado.web.authenticated
def get(self, nid):

    # Retrieve the current user 
    usr = self.get_current_user()
    usr_id = usr['id']

    self.lock_tables("read", ['nets_permissions as n'])
    perm = self.db.get("SELECT n.perm FROM nets_permissions as n \
                          WHERE n.network_id=%s AND n.user_id=%s", nid, int(usr_id))
    self.unlock_tables()

    # Check whether the user has access to the network
    perms = self.check_network_access(nid, perm['perm'])
    net = self.get_network(nid)
    # Render the networks page
    self.render("networkstatus.html", net=net)

与self.db.get还有perm['perm']。谢谢您!!!!在

相关问题 更多 >