I want to access APIs from application. Those APIs has decorator @auth.requires_login()
.
I am calling api from controller using
demo_app/controllers/plugin_task/task
url = request.env.http_origin + URL('api', 'bind_task')
page = urllib2.Request(url)
page.add_header('cookie', request.env.http_cookie)
response = urllib2.urlopen(page)
Demo API
api.py
@auth.requires_login()
@request.restful()
def bind_task():
response.view = 'generic.json'
return dict(GET=_bind_task)
def _bind_task(**get_params):
return json.dumps({'status': '200'})
Above code gives me error : HTTPError: HTTP Error 401: UNAUTHORIZED
How to solve this issue? I need to add any other headers?
Directory structure-
Demo_app
|
|-controllers
|
|-api.py
|-plugin_task.py
controller plugin_task.py
calls bind_task()
which is in api.py
EDIT:
Application .w2p file- Download