我是一名学生,我正在寻求调用 Jdoodle 的编译器 API(此处为文档)的帮助。
当我通过 Postman 发出发布请求并将其用作 JSON 正文时,它可以工作......
{
"script": "console.log('hello world')",
"stdin": "",
"language": "nodejs",
"versionIndex": "0",
"clientId": "a3462eccc82ecc57a745a23e52c5c71e",
"clientSecret": "another long string"
}
...我得到了我期望的输出:
{
"output": "hello world\n",
"statusCode": 200,
"memory": "22764",
"cpuTime": "0.05"
}
但是,我不能让它从我的 Python Flask 后端工作。这是我的代码:
@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()
我也通过传入标题(headers = {“Content-Type”:“application / json”})尝试了这个,我仍然从邮递员那里得到相同的响应:
{
"error": "Invalid Request",
"statusCode": 400
}
我是新手,任何帮助将不胜感激。谢谢!