Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:44:37+00:00 2026-06-06T06:44:37+00:00

I am trying to do a POST request using tastypie in django. My Resource

  • 0

I am trying to do a POST request using tastypie in django.

My Resource looks like below:

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']

And I am posting data like below:

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)

I am always getting 401, any idea?
What I am doing wrong?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:44:38+00:00Added an answer on June 6, 2026 at 6:44 am

    You will need to set

    Authorization=Authorization()
    

    The default authorization implmented by tastypie is

    ReadOnlyAuthorization()
    

    which results in, you guessed it, readonly results, hence it will cause errors.

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

    Do take note that it is not the best practice to do that however. There are other methods of Authorizations that can be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to POST a http request using ajax, but getting a response from
I am trying so sniff a multi-part POST request using Wireshark. When viewing the
I am trying to create a post request to the tumblr api. Shown below
Trying to send POST request on click event using jQuery with no luck. Here
Here are my resources: class CourseResource(ModelResource): subjects = fields.ToManyField('core.api.SubjectResource', 'subjects', full=True) class Meta: queryset
I am trying to mock the server response for a POST request using Sinon.js.
I'm trying to cache the request.POST dict using the low-level cache API, but it
So I'm using this plugin: jquery-in-place-editor , I'm trying to make a POST request
I am trying to analyze a POST request using firebug. Using the net panel
I'm trying to make a post request via ajax using jQuery (for the BaseCamp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.