开发者

How to debug django-piston application?

开发者 https://www.devze.com 2023-02-25 09:27 出处:网络
My piston application works correctly when I run it locally with python manage.py runserver command but returns

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:

  1. Setting my handlers to use Basic Authentication, even if I'm normally using something else.
  2. Use curl to make requests
  3. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消