I am trying to create a client and upload an image in Form React Component, when I send it to the backend using Axios I get the message "POST http://127.0.0.1:8000/ 400 (Bad Request)". If I create a client using postman, It creates it but when I do it in my React App, I get the 400 message. Does someone know what to do?
Related
I tried a bunch of tutorials, here is an example of one of them
https://nickmccullum.com/build-facebook-bot-python-flask/
Request is send:
127.0.0.1 - - [02/May/2022 10:18:15] "GET /?hub.mode=subscribe&hub.challenge=646416116&hub.verify_token=YOUR_VERIFY_TOKEN HTTP/1.1" 200 -
But when trying to validate, the Webhook throws this error:
Validation of the callback URL or confirmation token failed. Confirm the information provided or try again later.
what could be the problem
I'm trying to add twitter sign in option to my python application and I'm getting following error from web server:
GET /social-auth/login/twitter/ HTTP/1.1" 500 103190 403 Client Error: Forbidden for url: https://api.twitter.com/oauth/request_token
I work on dev environment django + unicorn with SSL on localhost. I've checked following instruction on Twitter callback url's guide:
Don’t use localhost as a callback URL Instead of using localhost, please use a custom host locally or http(s)://127.0.0.1.
My callback URL: https://127.0.0.1:8000/social-auth/complete/twitter/
Is it possible to make it work without hosting real domain?
Yes, you can test your API on the development server.
Try this one:
https://localhost:8000/complete/twitter/
or
https://127.0.0.1:8000/complete/twitter/
Update your callback URL in your App's Setting.
Refer to this article for more understanding :
https://github.com/python-social-auth/social-app-django/issues/164
I've defined custom templates for errors 400, and 404 for my Django project. When I try to access the production version of my site, the error 404 template is correctly loaded for missing pages. However, if I send a bad request to my Apache/Django server (e.g. http://mysite.example.com/%), the template for the error 400 is not loaded, instead, the regular Apache error page is rendered:
Bad Request
Your browser sent a request that this server could not understand.
Apache/2.4.18 (Ubuntu) Server at mysite.example.com Port 80
Is apache relaying this request to Django at all, or do I need to define handler400 in my Django project in order for this to work (though I didn't have to do that for the 404.html)?
The crucial point here is that your apache is acting as a proxy for your usgi server. It's forwarding all valid requests to usgi, a request for a non existent request is a valid request as far as apache is concerned and needs the forwarded to the django router - which will find that the url mapping does not exist and raise a 404 error. This error is done internally by django and results in the django 404 page being shown.
Some requests, most notably the django rest framework produce 400 responses internally when the serializers fail to validate the incoming json request. Those will also result in the django 400 page being shown.
However if the request itself is malformed, it will never be forwarded to the usgi server and django will never see it. it will be handled internally by apache hence the reason that the apache 400 html is shown.
The simplest solution would be to replace all the apache error pages with the corresponding django one (if these are templates, render them and save the html)
I'm using chrome-extension Postman for sending HTTP POST requests to my Django web application. The request is received successfully on my web app and after handling the request, when I send the HTTP response back, it shows the response on the Postman but I expect it to send on my web application so that some result is displayed (contents)
return render_to_response("logs/logs.html", {'contents': contents}, context_instance=RequestContext(request))
How can I achieve this? Thanks
I wrote my own custom client which sends raw http requests via my wifi card to my flask webserver.
This is what a typical requests looks like:
Content-Length: 214
User-Agent: blah
Connection: close
Host: 1.2.3.4:5000
Content-Type: application/json
{"data":[{"scoutId":2,"message":"ph=5.65"},{"scoutId":4,"message":"ph=4.28"},{"scoutId":3,"message":"ph=4.28"},{"scoutId":2,"message":"ph=5.65"},{"scoutId":4,"message":"ph=4.28"},{"scoutId":3,"message":"ph=4.30"}]}
Sometimes, my clients screw up and send malformed JSON requests to my flask server. Typically, flask will just display:
1.2.3.5 - - [01/Sep/2014 22:13:03] "POST / HTTP/1.1" 400 -
and nothing informative about the request.
I would like to track every single request that resulted in 400 in my environment and analyze what is causing these errors.
Where can I place my custom error function in my flask server?
Try turning this on:
app.config['TRAP_BAD_REQUEST_ERRORS'] = True
This should make flask raise an exception instead of just logging the 400 (see documentation here).
If you need to do something more than that, make an event handler:
http://flask.pocoo.org/docs/0.10/patterns/errorpages/
#app.errorhandler(400)
def page_not_found(exc):
#do something with the exception object `exc` here
....
Or try wrapping the body of your view function in try/except.