Could I please ask someone with Apache/mod_wsgi to test this code? Everything works fine on a local rocket webserver, and also on nginx, but for some reason when it runs on Apache returns "Not authorized". I just can't figure out where exactly is the problem. Same Apache server runs several web2py applications perfectly fine.
db=DAL() from gluon.tools import Auth auth = Auth(db).define_tables(username=True) if db(db.auth_user).isempty(): auth.get_or_create_user(dict( username='mdp', email='a...@b.com', password=db.auth_user.password.validate('test')[0])) response.generic_patterns = ['*'] auth.settings.allow_basic_login = True @request.restful() @auth.requires_login() def demo(): def GET(): return dict(hello='world') return locals() Call: curl --user mdp:test " http://127.0.0.1:8000/test3/default/demo.json Does this work for you? Thanks, Adnan On Thursday, October 11, 2012 6:00:30 PM UTC-4, Adi wrote: > > Thanks Massimo for looking into this. > > ticket opened: > > http://code.google.com/p/web2py/issues/detail?id=1080&thanks=1080&ts=1349992678 > > > On Thu, Oct 11, 2012 at 5:05 PM, Massimo Di Pierro wrote: > >> Please open a ticket about this and I will look in detail asap. >> >> >> On Thursday, 11 October 2012 09:44:04 UTC-5, Adi wrote: >> >>> Tried 2.09 nightly build on a completely different (redhat) server and >>> still getting redirect, while post works as expected on a local rocket. >>> >>> Any hint where to look for a problem please? >>> >>> using: >>> curl --user webserv...@domain.com:pass -d "FirstName=Tim5&LastName=Json"http >>> ://crm.domain.com/api/**customer.json<http://crm.domain.com/api/customer.json> >>> >>> You are being redirected <a href="/crm/default/user/login?** >>> _next=/crm/webservices/api/**customer.json >>> >>> Thanks, >>> Adnan >>> >>> >>> On Wed, Oct 10, 2012 at 10:46 AM, Adi < wrote: >>> >>>> This is an example from book, where authentication and posting into >>>> database work good on a local server. >>>> >>>> Once I moved the code to production redhat linux server, where we have >>>> routes.py as bellow all I get as result is a login redirect: >>>> You are being redirected <a href="/user/login?_next=/** >>>> webservices/api/customer.json%**3FFirstName%3DTim5%26LastName%**3DJson" >>>> >here</a> >>>> >>>> If I remove authentication (@auth.requires_login() and >>>> @auth.requires_permission('**insert customer through webservice')) on >>>> production server, records are inserted properly. >>>> >>>> Tried adding default and webservices controllers into application >>>> specific routes.py, but it didn't help. >>>> >>>> Any suggestions what should I do? >>>> >>>> Thanks, >>>> Adnan >>>> >>>> tried in both, default.py and webservices.py controllers: >>>> >>>> auth.settings.allow_basic_**login = True >>>> @auth.requires_login() >>>> @auth.requires_permission('**insert customer through webservice') >>>> @request.restful() >>>> def api(): >>>> response.view = 'generic.'+request.extension >>>> >>>> def GET(*args,**vars): >>>> patterns = [ >>>> "/members[customer]", >>>> "/member_fn/{customer.**FirstName.startswith}", >>>> "/member_ln/{customer.**LastName.startswith}", >>>> "/member/{customer.FirstName}/**:field", >>>> "/member/{customer.FirstName}/**orders[customer_order.** >>>> customer_id]", >>>> "/member/{customer.FirstName}/** >>>> order[customer_order.customer_**id]/{customer_order.id}", >>>> "/member/{customer.FirstName}/** >>>> order[customer_order.customer_**id]/{customer_order.id}/:**field" >>>> ] >>>> parser = db.parse_as_rest(patterns,args**,vars) >>>> if parser.status == 200: >>>> return dict(content=parser.response) >>>> else: >>>> raise HTTP(parser.status,parser.erro**r) >>>> def POST(table_name,**vars): >>>> if table_name == 'customer': >>>> return db.customer.validate_and_**insert(**vars) >>>> elif table_name == 'customer_order': >>>> return db.customer_order.validate_**and_insert(**vars) >>>> else: >>>> raise HTTP(400) >>>> return locals() >>>> >>>> >>>> >>>> >>>> >>>> web2py folder: routes.py >>>> routers = dict( >>>> # base router >>>> BASE = dict( >>>> default_application = 'welcome', domains = {'crm.domain.com': >>>> 'crm' } >>>> ), >>>> ) >>>> >>>> >>>> >>>> crm app folder: routes.py (deleted) >>>> >>>> >>>> Terminal test: >>>> >>>> >>>> asm21:~ adnan$ curl --user webserv...@domain.com:pass -d >>>> "FirstName=Tim5&LastName=Json" http://crm.domain.com/api/** >>>> customer.json <http://crm.domain.com/api/customer.json> >>>> Result: You are being redirected <a href="/user/login?_next=/api/** >>>> customer.json%3FFirstName%**3DTim5%26LastName%3DJson">here**</a> >>>> >>>> asm21:~ adnan$ curl --user webserv...@domain.com:pass -d >>>> "FirstName=Tim5&LastName=Json" http://crm.domain.com/webservi**ces/api/ >>>> customer.json >>>> Result: You are being redirected <a href="/user/login?_next=/** >>>> webservices/api/customer.json%**3FFirstName%3DTim5%26LastName%**3DJson" >>>> >here</a> >>>> >>>> >>>> >>>> >>>> >>>> -- >> >> >> >> > > > --