1

当我使用 python manage.py runserver 命令在本地运行我的活塞应用程序但返回时,我的活塞应用程序工作正常但返回

urllib2.HTTPError:HTTP 错误 403:禁止

在阿帕奇下。如何调试 django-piston 应用程序?

4

1 回答 1

0

我通常通过以下方式调试活塞应用程序:

  1. 将我的处理程序设置为使用基本身份验证,即使我通常使用其他东西。
  2. 使用curl发出请求
  3. 如果需要,使用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只要您想使用基本身份验证,就可以进行设置。

于 2011-09-30T20:13:04.823 回答