web2py - Restful API with authentication -


i try built api web2py application.

# -*- coding: utf-8 -*- auth.settings.allow_basic_login = true  @auth.requires_login() @request.restful() def api():     response.view = 'generic.json'      def get(tablename, id):         if not tablename == 'division':             raise http(400)           result = db(db.division.title == id).select()          return dict(result = result)  return locals() 

but everytime try connect via curl answer:

you being redirected <a href=\"/my_manager/login?_next=/my_manager/api/get_all_divisions/1.json\">here</a> 

when comment out line

@auth.requires_login() 

everythink works fine.

i've searched hints, didn't found helpful information topic far.

any appreciated.

i know pretty old question still answer other people might experience same issue:

well in case using @auth.requires_login() needs user logged in.

so need send basic auth credentials while making calls api.

a simplest curl call can be:

curl --user abc@example.com:abc123 http://localhost:8000/app_name/default/api/table_name.json 

here:

  • abc@example.com username
  • abc123 password
  • app_name web2py's app name
  • table_name table name in db

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -