My piston application works correctly when I run it locally with python manage.py runserver command but returns
开发者_如何转开发urllib2.HTTPError: HTTP Error 403: FORBIDDEN
under apache. How can I debug django-piston application?
I usually debug Piston apps by:
- Setting my handlers to use Basic Authentication, even if I'm normally using something else.
- Use curl to make requests
- Use pdb (or ipdb) to set a breakpoint in my handler if desired.
You can conditionally change to BasicAuthentication like this:
auth = {'authentication': WhateverYouAreUsingForAuthentication(realm="YourSite")}
if getattr(settings, "API_DEBUG", None):
from piston.authentication import HttpBasicAuthentication
auth = {'authentication': HttpBasicAuthentication(realm="Spling")}
some_handler = Resource(SomeHandler, **auth)
To pass a username and password using curl, use the -u
option:
curl -u username:password http://localhost:8000/api/some/endpoint/
So in your local settings module, just set API_DEBUG=True
whenever you want to use basic auth.
精彩评论