Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:28:18+00:00 2026-06-11T01:28:18+00:00

I have those variables: PERM_READ = 0x01 PERM_WRITE = 0x02 PERM_CMDS = 0x04 and

  • 0

I have those variables:

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

and a function that check the permission on a network or on a sensor. A function that determines what is the permission of the user.

This is the function:

def check_network_access(self, network, access=None, raise_err=True):
    if access is None:
        access = PERM_READ
    else:
        assert(access > 0)
        assert(access <= (PERM_READ + PERM_WRITE + PERM_CMDS))
    usr = self.get_current_user()
    usr_id = usr['id']
    # Does the network exist?
    net = self.get_network(network)
    if not net:
        raise tornado.web.HTTPError(404, "not found")

    self.lock_tables('read', ['nets_permissions'])
    perms = self.db.get("SELECT * FROM nets_permissions WHERE network_id=%s AND \
                        user_id=%s", network, usr_id)
    self.unlock_tables()
    if (not perms) or ((perms['perm'] & access) != access):
        if (raise_err):
            raise tornado.web.HTTPError(403, "access forbidden")
        else: 
            return False
    return True

Now for example i have an error when I call a page with this handler:

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)

The error I have is:

Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/tornado/web.py", line 988, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/tornado/web.py", line 1739, in wrapper
    return method(self, *args, **kwargs)
  File "./wsn.py", line 663, in get
    perms = self.check_network_access(nid, perm)
  File "./wsn.py", line 250, in check_network_access
    assert(access <= (PERM_READ + PERM_WRITE + PERM_CMDS))
AssertionError

I think this is a problem in the casting of the variable perm, when it’s passed to the check_network_access function…

Thank you for the help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:28:20+00:00Added an answer on June 11, 2026 at 1:28 am

    You need to use self.db.get instead of self.db.query. Something like the following should work:

    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']
    
        row = 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))
        perm = row['n.perm']
    
        # 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)
    

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my init I have set some variables and one animate that uses those
I have a function in a functions.php file that defines certain variables: add_action( 'the_post',
I have a JavaScript, which returns 2 variables. I just want to access those
I have certain PHP class methods that access external variables. These variables are not
Suppose that I have those three files: a.h //a.h header #include <stdio.h> int int_variable;
I have tool that creates variables for a simulation. The current workflow involves hand
I have some ENV variables that are sourced for the deploy user. (Similar to
I'm trying to pass local variables to an inline function in javascript and have
I have an applet that allows the user to define values for 10 variables,
Well I have those 2 variables, an NSString and an NSMutable Array which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.