Tastypie使用No-Op身份验证和授权为POST返回401

时间:2013-12-15 05:13:25

标签: python django curl tastypie

我尝试使用POST请求更新Tastypie中的某些数据。

这是我一直在尝试的Curl命令:

curl -b cookies -v --data '{ "name" : "test" }' -H "X-CSRFToken: VhPYwzz4NJXnTPgkfSuSAQnN3HZ5AJj0" -H "Content-Type: application/json" -X POST http://localhost:8000/api/v1/schedules/

我的资源如下:

class ScheduleResource(ModelResource):
    class Meta:
        queryset = Schedule.objects.all()
        resource_name = 'schedules'
        authentication = Authentication()
        authorization = Authorization()

当然,我的模型中有一个名为:

的字段
class Schedule(models.Model):
    name = models.CharField(max_length=64, blank=False, default="Default Schedule")

无论如何,这是我运行curl命令时发生的事情:

> POST /api/v1/schedules/ HTTP/1.1
> User-Agent: curl/7.30.0
> Host: localhost:8000
> Accept: */*
> Cookie: csrftoken=VhPYwzz4NJXnTPgkfSuSAQnN3HZ5AJj0; sessionid=q7vp6wkn2x5gy1036ibdnhbb0lexe3ac
> X-CSRFToken: VhPYwzz4NJXnTPgkfSuSAQnN3HZ5AJj0
> Content-Type: application/json
> Content-Length: 19
> 
* upload completely sent off: 19 out of 19 bytes
* HTTP 1.0, assume close after body
< HTTP/1.0 401 UNAUTHORIZED
< Date: Sun, 15 Dec 2013 05:07:55 GMT
< Server: WSGIServer/0.1 Python/2.7.5
< Content-Type: text/html; charset=utf-8

我的假设是我没有发送正确的数据。有什么想法吗?

0 个答案:

没有答案