簡體   English   中英

Django tastypie發布請求獲取401

[英]Django tastypie post request getting 401

我正在嘗試使用Django中的tastypie進行POST請求。

我的資源如下所示:

class TestResource(ModelResource):
    class Meta:
        queryset = Test.objects.all()
        resource_name = 'test'
        serializer = Serializer(formats=['json','xml'])
        always_return_data = True
        detail_allowed_methods = ['get', 'post', 'put', 'delete']

我發布如下數據:

import sys
import requests


DATA = {'field1':'posting data', 'field2':'123', 'field3':330303,}

def post(data):
    url = 'http://127.0.0.1:8000/api/test/'
    logging = {'verbose':sys.stderr}
    response = requests.post(url,data=data,config=logging)
    print "RESPONSE STATUS", response.status_code
    print "RESPONSE HEADERS", response.headers



if __name__=='__main__':
    post(DATA)

我總是收到401,知道嗎? 我做錯了什么?

提前致謝。

您將需要設置

Authorization=Authorization()

tastypie實施的默認授權為

ReadOnlyAuthorization()

您猜到它導致只讀結果,因此將導致錯誤。

http://django-tastypie.readthedocs.org/en/latest/tutorial.html

請注意,但這不是最佳做法。 可以使用其他授權方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM