Hi,
I am using a python script to organize some data and try to send it into 
web2py via the @request.restful() api.  In the python script the text is 
mainly input from a free form text field.  ( I believe some Unicode 
characters are in there as well, however I remove everything that is ord 
128 and above.) 

My problem arises when the text contains an ampersand (&) and probably 
anything that isn't allowed in without the form encoding.  I thought python 
json would escape the character some way but it does not seem to.

I am trying to use json to transfer this data to web2py via the curl 
command within python.

Python Script

import json
import subprocess


url = 'http://127.0.0.1:8000/testing/default/api/people.json'
data = {"name":"My Full Name","biography":"Some simple information\n about 
me & blah blah blah"}


jsondata = json.dumps(data)
result = subprocess.Popen(['curl',
   '--user','username:password',
   '-d',
   jsondata,
   url], stderr=subprocess.PIPE,stdout=subprocess.PIPE).communicate()[0]





The web2py relevant parts

db.py

db.define_table('people',
    Field('name','string',length=200,requires=IS_NOT_EMPTY()),
    Field('biography','text'))


default.py


auth.settings.allow_basic_login=True
@auth.requires_login()
@request.restful()
def api():
    response.view = 'generic.' + request.extension
    def POST(table_name,**vars):
        if table_name == 'people':
            return db.people.validate_and_insert(**vars)
        else:
            raise HTTP(400)
    return locals()


So when the python script sends the data web2py complains because of the 
escaping issue with the & in the data.  I was doing some searching and 
thought that changing the Content Type in the curl command to 
application/json would help with this but then web2py has nothing in the 
vars variable.

Thank you,
Brent

-- 

--- 
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/groups/opt_out.


Reply via email to