问题描述
|
当我使用python manage.py runserver命令在本地运行时,我的活塞应用程序可以正常工作,但返回
urllib2.HTTPError:HTTP错误403:
禁止的
在Apache下。如何调试django-piston应用程序?
解决方法
我通常通过以下方式调试Piston应用程序:
将我的处理程序设置为使用基本身份验证,即使我通常使用其他身份验证也是如此。
使用curl发出请求
如果需要,可以使用pdb(或ipdb)在我的处理程序中设置断点。
您可以像这样有条件地更改为BasicAuthentication:
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)
要使用curl传递用户名和密码,请使用-u
选项:
curl -u username:password http://localhost:8000/api/some/endpoint/
因此,在您的本地设置模块中,只要您想使用基本身份验证即可设置API_DEBUG=True
。