[web2py] Re: json to request.vars
In jQuery, if you do: data: {json1: JSON.stringify([1, 2, 3])}, contentType: 'application/json' Then in the controller, request.post_vars.json1 will be the Python list, [1, 2, 3] -- no need to do any JSON conversion on the server side. Note, the JSON must be an object with keys, not simply an array -- otherwise web2py will not treat it as JSON and convert it to a Python data structure. If the JSON has keys, the keys will become the keys of request.post_vars. Anthony On Sunday, February 4, 2018 at 9:41:48 PM UTC-5, lucas wrote: > > hey all and anthony, > > i've tried a bunch of things, including your suggestion above. here are > my results and this is using web2py 2.16.1. on the client side, under the > view's header, i have: > > a = getArray(); > //displays the grabbed array > > //jQuery('div#snapshot_matrix').html(snapshot_table+''+JSON.stringify(a, > > null, '\t')+'').css('display', 'block'); > jQuery.post({url:"{{=URL(c='main321911', > f='ajaxAnalysesSummary1')}}", data:{ 'json1':JSON.stringify([1, 2, 3]) } > }).done(function (t) { > > //jQuery('div#snapshot_matrix').html('server_return:\n'+JSON.stringify(t, > > null, '\t')+'').css('display', 'block'); > > jQuery('div#snapshot_matrix').html('server_return:\n'+t+'').css('display', > > 'block'); > > where a or getArray() just reads the values of various inputs and slams > them into a javascript/json object with the declaration "var a = { };" > which to me is similar to a python dict. the jQuery.post is the method i > used to transfer the array to the server and under the post function i've > tried various permutations on data with and without the option > ..."contentType: 'application/json', "... present or not. the various > permutation of data were: > > data: a, > data: JSON.stringify(a), > data: { json1:[1, 2, 3] }, > data: { 'json1':[1, 2, 3] }, > data: { json1:JSON.stringify([1, 2, 3]) }, > data: { 'json1':JSON.stringify([1, 2, 3]) }, > > and many others. on the server side, i just have: > > def ajaxAnalysesSummary1(): > #from gluon.contrib import simplejson > dct = { 'ajaxAnalysesSummary1':True } > get = request.vars > dct['len1'] = len(get) > dct['type1'] = type(get) > dct['get1'] = get > get = request.post_vars > dct['len2'] = len(get) > dct['type2'] = type(get) > dct['get2'] = get > > get = loads(request.vars.json1) > dct['len3'] = len(get) > dct['type3'] = type(get) > dct['get3'] = get > get = request.post_vars.json1 > dct['len4'] = len(get) > dct['type4'] = type(get) > dct['get4'] = get > return DIV(dct) > > where the client will display the dct of type dict passed to DIV. > > the only way that consistently works is when i use JSON.stringify(a) on > the client side, both 2nd and last, worked under the above data options, > and loads on the server side. the loads will convert the pure "a" json > object, in the 2nd data option, to a proper addressable python dict, or as > json1 variable converted with the python dict under that variable. the > values of the dict still have to be processed into int or double depending > on their twins on the db side. > > but in every permutation, setting the option of "contentType: > 'application/json'" returned no data under request.vars or > request.post_vars. > > so, i believe i go with the working model of JSON.stringify on the client > side with loads on the server side. makes sense and i believe a solid > solution. > > lucas > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] About Rest API uploads (again)
Hi everyone, this is something that has been asked several times and still there's no specific solution. I need to upload files by using a Rest API, so far I know we have nice ways to implement our apps in web2py http://www.web2pyslices.com/slice/show/1533/restful-api-with-web2py is one way, simple and clean. the other one is http://experts4solutions.com/collection2/default/examples both work perfectly fine wiith regular form data, as it comes with uploads they dont. following the recipe from Bruno I can upload files by using curl like this curl POST -F "name=myfile" -F "image=@/home/user/myimgfile.png" http://127.0.0.1:8000/myapp/services/api/uploadimg and it works. In this new project I need to upload several images and some other format files (csv, doc, pdf, xls), as now I'm working with Vue.js and Axios it would be awesome (and somehow faster) applying it. when I try to send the request using axios in this way let img=e.target.files; let formData = new FormData(); formData.append('file', img[0]); axios.post('../services/api/uploadimg',{ name:'test from axios', image:formData }, { headers: { 'Content-Type': 'multipart/form-data' } }) .then((response)=>{console.log('file uploaded');}) .catch((error)=>{console.log(error);}); } server returns an error Traceback (most recent call last): File "/home/user/web2py/gluon/restricted.py", line 219, in restricted exec(ccode, environment) File "/home/user/web2py/applications/myapp/controllers/services.py", line 50, in File "/home/user/web2py/gluon/globals.py", line 414, in self._caller = lambda f: f() File "/home/user/web2py/gluon/globals.py", line 377, in f res = rest_action(*request.args, **request.vars) File "/home/user/web2py/gluon/globals.py", line 309, in vars self.parse_all_vars() File "/home/user/web2py/gluon/globals.py", line 280, in parse_all_vars for key, value in iteritems(self.post_vars): File "/home/user/web2py/gluon/globals.py", line 301, in post_vars self.parse_post_vars() File "/home/user/web2py/gluon/globals.py", line 237, in parse_post_vars dpost = cgi.FieldStorage(fp=body, environ=env, keep_blank_values=1) File "/usr/lib/python2.7/cgi.py", line 507, in __init__ self.read_multi(environ, keep_blank_values, strict_parsing) File "/usr/lib/python2.7/cgi.py", line 621, in read_multi raise ValueError, 'Invalid boundary in multipart form: %r' % (ib,) ValueError: Invalid boundary in multipart form: ' couln't find much on that error but an old post in this group from 2012 https://groups.google.com/forum/#!topic/web2py/ixeUUWryZh0/discussion Any suggestions?, meanwhile I'm still trying to make it work. Greets. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: json to request.vars
hey all and anthony, i've tried a bunch of things, including your suggestion above. here are my results and this is using web2py 2.16.1. on the client side, under the view's header, i have: a = getArray(); //displays the grabbed array //jQuery('div#snapshot_matrix').html(snapshot_table+''+JSON.stringify(a, null, '\t')+'').css('display', 'block'); jQuery.post({url:"{{=URL(c='main321911', f='ajaxAnalysesSummary1')}}", data:{ 'json1':JSON.stringify([1, 2, 3]) } }).done(function (t) { //jQuery('div#snapshot_matrix').html('server_return:\n'+JSON.stringify(t, null, '\t')+'').css('display', 'block'); jQuery('div#snapshot_matrix').html('server_return:\n'+t+'').css('display', 'block'); where a or getArray() just reads the values of various inputs and slams them into a javascript/json object with the declaration "var a = { };" which to me is similar to a python dict. the jQuery.post is the method i used to transfer the array to the server and under the post function i've tried various permutations on data with and without the option ..."contentType: 'application/json', "... present or not. the various permutation of data were: data: a, data: JSON.stringify(a), data: { json1:[1, 2, 3] }, data: { 'json1':[1, 2, 3] }, data: { json1:JSON.stringify([1, 2, 3]) }, data: { 'json1':JSON.stringify([1, 2, 3]) }, and many others. on the server side, i just have: def ajaxAnalysesSummary1(): #from gluon.contrib import simplejson dct = { 'ajaxAnalysesSummary1':True } get = request.vars dct['len1'] = len(get) dct['type1'] = type(get) dct['get1'] = get get = request.post_vars dct['len2'] = len(get) dct['type2'] = type(get) dct['get2'] = get get = loads(request.vars.json1) dct['len3'] = len(get) dct['type3'] = type(get) dct['get3'] = get get = request.post_vars.json1 dct['len4'] = len(get) dct['type4'] = type(get) dct['get4'] = get return DIV(dct) where the client will display the dct of type dict passed to DIV. the only way that consistently works is when i use JSON.stringify(a) on the client side, both 2nd and last, worked under the above data options, and loads on the server side. the loads will convert the pure "a" json object, in the 2nd data option, to a proper addressable python dict, or as json1 variable converted with the python dict under that variable. the values of the dict still have to be processed into int or double depending on their twins on the db side. but in every permutation, setting the option of "contentType: 'application/json'" returned no data under request.vars or request.post_vars. so, i believe i go with the working model of JSON.stringify on the client side with loads on the server side. makes sense and i believe a solid solution. lucas -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: web2py gunicorn dockerfile
done best regards, stifan -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: how to hash the a users password in bash script
pls try: *e.g.* *test/controllers/install.py (for running with curl)* def index(): if db(db.auth_permission).isempty() and db(db.auth_membership).isempty(): auth_user_id_1 = db.auth_user.insert(first_name = 'Admin', last_name = 'Admin', email = 'ad...@test.com', username = 'admin', password = db.auth_user.password.validate("yourpassword")[0] ) session.flash = T('Installation Done') redirect(URL('default', 'index') ) *test/modules/test_install.py (for running with python)* from gluon import current from gluon.contrib.webclient import WebClient install = WebClient('http://127.0.0.1:8000/test/install/', postbacks = True) install.get('index') if current.T('Log In', lazy = False) in install.text: print (current.T('Installation Done', lazy = False) ) else: print (current.T('Installation Failed', lazy = False) ) *then run in console (assumming web2py already running)* python ~/web2py/web2py.py --nogui --no-banner -S test -M -R ~/web2py/applications/test/modules/test_install.py or curl http://127.0.0.1:8000/test/install best regards, stifan -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Downloading ALL images in a table at once
I have a table which stores different images of different places, what i want is for the site users to be able to download all the images of a selected place by clicking the download button without having to download the images one at a time. How can i achieve this?? I tried this below: *MODEL:*db.define_table('location', Field('Image', 'upload'), Field('formTitle', requires=IS_NOT_EMPTY()), Field('place', 'reference area'),migrate=False,fake_migrate=True) *CONTROLLER*def areas(): form=db.place(request.args(0)) images=db(db.location.place==form.id).select(db.location.ALL) return dict(images=images, form=form) *VIEW*{{extend 'layout.html'}} {{for pics in images:}} Download {{pass}} Unfortunately the above attempts do not give me what i want, please assist. Thank you. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Update Web2Py from admin page > Error - from version 2.14.6
Hi, I tried to upgrade the easy way from the admin screen but now I get a ticket that I cannot read. At one point I get: Requires web2py 2.15.5 or newer I installed previously for the one step install (Linux). I tried again but I get a 404 error from: wget http://web2py.googlecode.com/hg/scripts/setup-web2py-ubuntu.sh Any ideas? Mike -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: how to hash the a users password in bash script
A few options: - Convert the bash script to a Python script. - From the bash script, call a Python script just to do the inserts (using PyDAL in the Python script). - From the bash script, call a Python script just to calculate the hashed password (using the web2py CRYPT validator), passing the value back to a bash variable. Anthony On Monday, January 22, 2018 at 10:10:07 AM UTC-5, lucas wrote: > > hello one and all, > > I'm creating a bash script that creates the new db with indexes, > functions, etc. using Postgresql 9.2 for the DAL to use in web2py 2.16.1. > > as it stands now, the script works great and even creates the tables > properly as setup in db.py, etc. > > I would like to insert some users into auth_user under that bash script > like: > > #!/bin/bash > psql db postgres << EOF > insert into auth_user (first_name, last_name, email, password) values > ('Harry', 'Truman', 'htru...@gmail.com', w2p_hash_passwd('dude man')); > EOF > exit 1 > > the w2py_hash_passwd is obviously not real, but what would I replace it > with so that when harry types in the 'dude man' password, web2py hashes it > properly and logs in old harry? > > thank you in advance, lucas > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [web2py] Re: Switching database backend from sqlite to mysql
Adding the line `db._adapter.reconnect()` to the top of the function seems to have solved the problem. Thanks so much for the help. On Sun, Feb 4, 2018 at 4:02 AM, LoveWeb2pywrote: > Hi Massimo, > > Thank you for responding. Do you have an example? I am having the same > struggle. > > Thank you again. > > On Sunday, February 4, 2018 at 12:46:08 AM UTC-5, Massimo Di Pierro wrote: >> >> I believe the problem is that pydal is designed to not allow db to be >> shared among multiple threads to avoid concurrency issues. Every thread >> should make its own db object or, if you pass db around, you should call >> db.reconnect in each thread. >> >> On Saturday, 3 February 2018 22:14:41 UTC-6, jbu...@wgu.edu wrote: >>> >>> The attached file contains the code that is generating the error, line 4 >>> specifically is called out in the traceback, but if I comment this line out >>> I get the same error from the next line that is querying the database. If I >>> start a web2py shell, I can copy and paste the offending line into the >>> shell and it returns the expected results, also if I switch the database >>> back to sqlite everything works as expected. >>> >> -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/web2py/iJvGzWEd3pU/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Jonathan Burkert Student ID: 744966 BS in Data Management and Data Analytics 2017-10-01 Mentor: Tom Grant c 717-318-9998 Eastern jbur...@wgu.edu -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[web2py] Re: Switching database backend from sqlite to mysql
Hi Massimo, Thank you for responding. Do you have an example? I am having the same struggle. Thank you again. On Sunday, February 4, 2018 at 12:46:08 AM UTC-5, Massimo Di Pierro wrote: > > I believe the problem is that pydal is designed to not allow db to be > shared among multiple threads to avoid concurrency issues. Every thread > should make its own db object or, if you pass db around, you should call > db.reconnect in each thread. > > On Saturday, 3 February 2018 22:14:41 UTC-6, jbu...@wgu.edu > wrote: >> >> The attached file contains the code that is generating the error, line 4 >> specifically is called out in the traceback, but if I comment this line out >> I get the same error from the next line that is querying the database. If I >> start a web2py shell, I can copy and paste the offending line into the >> shell and it returns the expected results, also if I switch the database >> back to sqlite everything works as expected. >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.