Django-rest post returns get - django-rest-framework

I built out an API with django-rest, tested it on a local machine, and pushed it to my PaaS. On my local machine a view associated with a post works perfectly. The live site throws an error.
Decorator for view in question: #api_view(['POST'])
Error: u'{"detail":"Method \\"GET\\" not allowed."}'.
Python Request Module snippet (note POST not get):
r = requests.post(my_url, data=json.dumps(payload), headers=headers, verify=False)
Server log: "POST /api/xxx/xxx/ HTTP/1.1" 301
No errors in the server log, no errors in the django-rest API. The post to the function does work on the browsable API. Why am I receiving a GET error on a post? I've tried things in curl and receive the same error. What's going on?

Got it. Move from http to https wasn't reflected in the URL.

Related

API call returns a response in postman but gives me 403 in browser

ajax call
postman url
console error
Postman returns a response, but browser gives me 403. I have attached my postman request, my ajax call as well as the browser error. Any advice is helpful
You need to pass credentials. follow this link for more information.
I ran into this issue as well. While cedric is right, the Authorization header needs to be specified, another issue can cause this as well. Postman does not include an Origin header in its requests (see: https://stackoverflow.com/a/68380707/1029688). This could cause it to ignore CORS errors that you would normally encounter when making web requests from a browser.

API server block request from GuzzleHttp

I have 2 servers which are API server and Client server ....
Both server using Google Cloud server and I use Laravel framework to develop my system...
So, currently the problem is, it return 403 error when calling API (to API server) using GuzzleHttp (from Client Server).....
But after I change the user agent to curl/7.65.3, suddenly it is working fine...
But I want to know why??? Is there any other solution without changing the user-agent???
Thanks
What is your use method? If GET you can refer to:
GET Requests That Include a Body
If a viewer GET request includes a body, CloudFront returns an HTTP status code 403 (Forbidden) to the viewer.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html

Endpoint Server GraphQL (overblog-GraphQLBundle) Not support Method POST

For 3 Days, my project which worked perfectly locally, once put on the production server.
GraphQl requests are a failure with the error "[Error: Network error: JSON Parse error: Unrecognized token '<']" and after log analysis it is a 404 error because the route was not found.
After investigation via the GraphQl Atlair client for chrome by changing the method to GET to make my GrasphQl requests, the error everything works.
my question is how to work the POST method?
I really need to use the METHOD POST for mutations
Thanks everyone
Very cordially
You forgot to add a trailing slash to your GraphQL endpoint URL.
Related issue (solved): https://github.com/overblog/GraphQLBundle/issues/669

django-rest-framework: how to allow http PUT to succeed

I have a startup django-rest-framework app, which I'm using to serve data to another Django app
I have no issues with GET, POST, and DELETE, but when I issue a PUT - I get 405
What can I do to fix that?
if I'm remembering well, I has the same issue. Following the tutorial of django-rest-framework I noticed that pressing PUT botton request and monitoring network tab of chrome developer tools it did a POST request instead of PUT request.
Maybe '405 METHOD NOT ALLOWED' error message caused by request without '/' at the end of the url.
Not working 127.0.0.1:8000/article/9
Working 127.0.0.1:8000/article/9/
If not, check how you request it. It's similar to request DELETE method.
This is an example I've just testing using PAW http client application
PUT Method request screenshot
PUT Method request result screenshot

Django REST framework API only working from the API project

I am developing a REST API for my application with django-rest-framework.
Everything works fine as long as I use either:
The browsable API
AJAX requests within a template in the same project where the API is being built
If I try to access the API from oustide the "master" project (the one I am building an API for), for instance from another Django project on the same machine, I am constantly getting an error.
Here is the trace from runserver for a successful API call:
[21/Nov/2014 12:11:01] "GET /api/test_session/ HTTP/1.1" 200 9208
The same endpoint but from outside the master project (it fails):
[21/Nov/2014 12:11:14] "GET /api/test_session/ HTTP/1.1" 200 58
I am using the ajax function of jQuery to send my API calls and I have set up the error callback. However the errorThrown that I receive is empty and the textStatus property only says "error".
How do I access my API from the oustide? I am using the default authentification backend (session based).
After some discussion it came to light that the error had to do with Cross Origin Resource Sharing policies.
A solution tailored for Django is to use django-cors-header, as recommended by the django REST framework documentation.

Resources