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 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?
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.
I have a strange issue with the TCP JSON-RPC server I've created in Python-2.7. I used the following code to build the server:
https://github.com/joshmarshall/jsonrpclib
I am communicating client to server from within the same local network. In the console window, I can connect to and run commands against the server from within Python. All is well there.
However, when I try to send JSON strings from a mobile app (in this case an iPad) I get an error on the server. I have also downloaded this tool in an attempt to send the JSON strings: http://www.simplecomtools.com/productcart/pc/downloads/tcptesttool.zip but with the same error result. The server is reporting a "Bad request syntax" error. I've tried several different strings - the displayed errors are:
192.168.1.107 - - [13/Oct/2012 09:48:17] code 400, message Bad request syntax ("{'jsonrpc':'2.0','method':'add','params':[3,6],'id':'8'}")
192.168.1.107 - - [13/Oct/2012 09:48:17] "{'jsonrpc':'2.0','method':'add','params':[3,6],'id':'8'}" 400 -
192.168.1.107 - - [13/Oct/2012 09:49:44] code 400, message Bad request syntax ('{"jsonrpc":"2.0","method":"add","params":[3,6],"id":"8"}')
192.168.1.107 - - [13/Oct/2012 09:49:44] "{"jsonrpc":"2.0","method":"add","params":[3,6],"id":"8"}" 400 -
192.168.1.107 - - [13/Oct/2012 09:50:49] code 400, message Bad request syntax ('{"jsonrpc":"2.0","method":"add","params":{"x":3,"y":6},"id":"8"}')
192.168.1.107 - - [13/Oct/2012 09:50:49] "{"jsonrpc":"2.0","method":"add","params":{"x":3,"y":6},"id":"8"}" 400 -
192.168.1.107 - - [13/Oct/2012 17:11:59] code 400, message Bad request syntax ("{'jsonrpc':'2.0', 'method':'add', 'params':{'x':3,'y':6}, 'id':8}")
192.168.1.107 - - [13/Oct/2012 17:11:59] "{'jsonrpc':'2.0', 'method':'add', 'params':{'x':3,'y':6}, 'id':8}" 400 -
I really have no idea why the server would think the request syntax is bad, and I feel a little silly even asking the question. Any ideas on what I could try to solve the syntax error?
In message 1 and 4, your client is not actually sending JSON; it is using ' to denote string boundaries, instead of ". While single quotes are supported by some JSON implementations, they are invalid according to the standard. Correct your client implementation to send actual JSON with "-delimited strings.
But the main problem is that you're not wrapping your messages into HTTP POST requests, but sending them raw. A proper JSONRPC request looks like:
POST / HTTP/1.0
Content-Length: 71
{"jsonrpc": "2.0", "params": [3, 6], "id": "er5qtdbz", "method": "pow"}
, but you're sending just the last line.
In Python, you can send a valid request with the following example program:
import json
try:
from urllib.request import urlopen
except ImportError: # Python<3
from urllib2 import urlopen
req = {"jsonrpc":"2.0","method":"add","params":[3,6],"id":0}
req_data = json.dumps(req).encode('utf-8')
u = urlopen('http://localhost:8080/', req_data)
print(u.read())
I have Django project on Dreamhost server which has several views that returns Json response.Yesterday I have ported my Django project from local machine(localhost) to dreamhost server running apache.Now if I call my django view through jquery for
http://www.abc.com/projects/
It should return me all projects that i have in my mongodb database but instead of that it returns :
On Firefox - just headers with no response
Connection Keep-Alive
Content-Type application/json
Date Thu, 19 Jan 2012 09:03:34 GMT
Keep-Alive timeout=2, max=100
Server Apache
Status 200 OK
Transfer-Encoding chunked
On Chrome - No headers and response data.It throws an error:
XMLHttpRequest cannot load http://abc.com/Projects/. Origin null is not allowed by Access-Control-Allow-Origin.**
If I just access the http://www.abc.com/projects/ through my web-browser it returns me results in json format,but not in case if I use JavaScript/Jquery.
Earlier I was using this middleware to allow other domains to request and get response on my local-machine with django in-built server.But now when I am running on apache server It stops working so I removed It from Settings.py file.
I don't know why is this error coming .Please help
*EDIT*
As #burhan suggested I used jsonp on client side and now my server is returning json but browser is giving error before parsing it.Error is : unexpected token
JSON i am getting in reply is :
{"projects": [{"projectName": "carmella", "projectId": "4f13c7475fcff30710000000"}, {"projectName": "SeaMonkey", "projectId": "4f1677b75fcff37c03000001"}]}
You are running into the same origin policy sandbox. Since your server is www.abc.com and you are accessing abc.com - the origin is not the same, which is why the script is not executing.
You have a few options:
Make sure the URL matches exactly - to avoid the same origin policy sandbox.
Use jsonp in your javascript libary.