Hi guys!

I was trying to execute a POST using ReST inside a function. This post has 
two fields. When I try to do it with a curl, it works fine, but when I do 
exactly the same POST inside a function, it gives me an error.

On my model:
db.define_table('algorithm',
                Field('name', 'string',length=255,unique=True),
                Field('description', 'text'),
                format='%(name)s')

And on my controller:

import requests
from requests.auth import HTTPBasicAuth

@request.restful()
def api():
    response.view = 'generic.'+request.extension

    def GET(*args,**vars):
        patterns = 'auto'
        parser = db.parse_as_rest(patterns,args,vars)
        if parser.status == 200:
            return dict(content=parser.response)
        else:
            raise HTTP(parser.status,parser.error)

    def POST(table_name,**vars):
        return db[table_name].validate_and_insert(**vars)

    def PUT(table_name,record_id,**vars):
        return db(db[table_name]._id==record_id).update(**vars)

    def DELETE(table_name,record_id):
        return db(db[table_name]._id==record_id).delete()
    return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)

def add_algorithm():
    """
    form to add new algorithms on database.
    """
    alg_form=SQLFORM.factory(Field('name', 
requires=IS_NOT_IN_DB(db,db.algorithm.name)),
                             Field('description'),
                             table_name='algorithm')

    if alg_form.accepts(request,session):
        payload = {'name':alg_form.vars.name, 
'description':alg_form.vars.description}
        r = 
request.post("http://127.0.0.1:8000/webpricer/default/api/algorithm.json";, 
data=payload, auth=('user', 'pass'))
        response.flash = payload
    elif alg_form.errors:
        response.flash = T('Please check for errors on form!')
    else:
        response.flash = T('Please fill the form')
    return dict(alg_form=alg_form)

When I click to submit the values, I receive the following error:
<type 'exceptions.TypeError'>('NoneType' object is not callable)

The variables are as follow:
global request     <Storage {'_vars': None, 'function': 
'add_algori...ueira/Downloads/web2py/applications/webpricer/'}>
request.post     None
global data     <function data>
global auth     <gluon.tools.Auth object>
r     undefined
payload     {'description': 'Description', 'name': 'webpricer'}

For sure I'm doing something dumb, but I'm stuck on this error some days 
and can't found what I'm doing wrong... Didn't find any related error on 
past topics.





-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to