Massimo,
Thanks for the reply. But it didn't work. I've this simple assign
function:


def assign():
    print request.vars

and it prints this. Note the \r\n as first characters. This is what is
causing the problem

<Storage {'\r\nfields': "{'case_id': 16, 'assign_to':
'age...@example.com"}>

Just for the ref, I'm using the below python script for sending
parameters.

data = {'fields': {'case_id': 16, 'assign_to': 'age...@example.com'}}

data = urllib.urlencode(data)
response = urllib2.urlopen(request,data).read()

Hope you can help me out. Thanks,
Joseph

On Apr 19, 8:10 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> The "assign" function expects the request.vars.fields to be in JSON.
> This should do it but I have not tried it.
>
> data = {'fields': simplejson.dumps({'case_id': 16, 'assign_to':
> 'age...@example.com'})}
> data = urllib.urlencode(data)
> response = urllib2.urlopen(request,data).read()
>
> Massimo
>
> On Apr 19, 5:55 am, Joseph Jude <ceph...@gmail.com> wrote:
>
> > Hi all,
> > I have a function as below. This is called as part of API function
> > rather than from the browser.
>
> > def assign():
> >     print request.vars.fields
> >     if request.vars.fields:
> >         case_values=json.loads(request.vars.fields)
> >         ret_dict=api.assign_case(db,case_values)
> >     else:
> >         ret_dict={'id': 1, 'msg': 'No parameters received'}
> >     return json.dumps(ret_dict)
>
> > When I invoke this via,
> > curl -u u...@example.com:web2pyhttp://localhost:8000/init/api/assign/
> > -d fields='{"id":16,"assign_to":"age...@example.com"}'
>
> > I do get request.vars.fields properly and the function executes as
> > desired. However when I try the same via a python script like the
> > below:
>
> > data = {
> >                 'fields': {'case_id': 16, 'assign_to': 'age...@example.com'}
> >                 }
>
> > data = urllib.urlencode(data)
> > response = urllib2.urlopen(request,data).read()
>
> > There is no input parameter (fields). When I examine the
> > request.vars.fields, it shows like the below:
>
> > <Storage {'\r\nfields': "{'case_id': 16, 'assign_to':
> > 'age...@example.com'%"}>
>
> > There are \r\n at the begining and % at the end. Is there a reason for
> > this? How can I test my function using python script (ie achieve the
> > same result as curl).
>
> > Hope my question is not too confusing.
>
> > Thank you,
> > Joseph
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to