python web2py controller request.vars doesn't have attribute (but actually does)

269 Views Asked by At

Python 2.7.12

web2py 2.14 stable

--call to controller developed by javascript

--call to controller. Captured by Chrome inspect

GET "http://127.0.0.1:8000/default/FoldBe.html?operation=get&id=%23"

--controller default.py

FoldBe():
    vars = dict(request.vars)
    print type(vars)
    #<type 'dict'>

    print vars
    #{'operation': 'get', 'id': '#'}

    for i in vars:
        print i
        #operation
        #id
        #print i.id

    print vars.id
    #ERRORS!!! stating.  What gives?
    #<type 'exceptions.AttributeError'> 'dict' object has no attribute 'id'

But the 'vars' dict obviously is a 'dict' and obviously has an 'id' attribute If i remark out print vars.id the view renders in the browser & no errors indicated as you would expect.

If I allow print i.id to execute the error is:

<type 'exceptions.AttributeError'> 'str' object has no attribute 'id'

What gives?

I have other methods in this controller and other controllers where this isn't a problem.

1

There are 1 best solutions below

1
On BEST ANSWER

You should access dictionary keys by name, so try vars['id'] instead of vars.id.