1

Many thanks for reading:

I have to following code in a .py file calling a web2py function within the default controller:

Snippet of code in .py running from IDLE - username and password are imported correctly

payload = {'username': username, 'password': password} 
r = requests.get('http://127.0.0.1:8000/webappfiletransfer/default/server_file_list_create.json/x/y/z', params=payload)

In web2py I have the following code to
1:Accept the username and password and
2:Compare them with saved in web2py username and password variables

The file containing username and password is parameters.py stored in myappfilefolder/modules/parameters.py within the web2py environment


EDIT: It seems that after a complete system restart there is the need to put parameters.py in web2py/site-packages as well, as I have found in several SO answers and regardless the fact that

Once a module "mymodule.py" is placed into an app "modules/" folder, it can be imported from anywhere inside a web2py application (without need to alter sys.path with):import mymodule

as the documentation states. Obviously I am missing something


parameters.py is

username="testacc"
password="1234"

Web2py Code is:

from gluon.custom_import import track_changes
track_changes(True)

import parameters

usrname = request.vars['username'] 
passwd =  request.vars['password']

if (usrname==parameters.username and passwd==parameters.password):  

Problem: Although I am using

from gluon.custom_import import track_changes
track_changes(True)  

which as I have understood forces a reload of the modules imported, the following behaviour is taking place:

In the first call from IDLE and if parameters are wrong in parameters.py I have the unauthorized message I have put to print, since the parameters are wrong.

Editing the file parameters.py with the correct username/password , I have a correct validation and a succesful return from web2py.

Editing again the file parameters.py and entering wrong credentials DOES NOT causes an error again and web2py returns corretly although wrong credentials are supplied. All subsequent calls return a successful result regardless the credentials.

Is there something I miss from using

 from gluon.custom_import import track_changes
track_changes(True)  

or something else I should consider in order to trigger a wrong validation again without closing first web2py.

0 Answers0