I'm a student, and I'm looking for help calling Jdoodle's compiler API (docs here), please.
When I make a post request through Postman and use this as the JSON body, it works...
{
"script": "console.log('hello world')",
"stdin": "",
"language": "nodejs",
"versionIndex": "0",
"clientId": "a3462eccc82ecc57a745a23e52c5c71e",
"clientSecret": "another long string"
}
...and I get the output I expect:
{
"output": "hello world\n",
"statusCode": 200,
"memory": "22764",
"cpuTime": "0.05"
}
However, I can't get it to work from my Python Flask back-end. Here is my code:
@app_bp.route("/compile", methods=["POST"])
def compile():
path = "https://api.jdoodle.com/v1/execute"
query_params = {
"script": "console.log('hello world')",
"stdin": "",
"language": "nodejs",
"versionIndex": "0",
"clientId": "a3462eccc82ecc57a745a23e52c5c71e",
"clientSecret": "another long string here similar to one above"
}
response = requests.post(path, params=query_params)
return response.json()
I've also tried this by passing in headers (headers = {"Content-Type" : "application/json"}), and I still get the same response from Postman:
{
"error": "Invalid Request",
"statusCode": 400
}
I'm a newbie, and any help would be greatly appreciated. Thank you!