我正在使用 Python 的请求模块通过 imgflip 的 API“生成 Meme”,但是在使用 boxes
时收到以下错误消息:
未指定文本。请记住,API 请求参数是 http 参数而不是 JSON。
这是我当前的代码:
boxes = [{"text": top}, {"text": bottom}]
params = {
"template_id": 181913649,
"username": username,
"password": password,
"font": "arial",
"boxes": boxes
}
meme = requests.post(url="https://api.imgflip.com/caption_image", params=params).json()
我已将框
格式化为他们希望的方式,如他们的文档中所述( https://imgflip.com/api )
所以我不知道为什么它不起作用......
最佳答案
目前您正在发送如下内容:
https://api.imgflip.com/caption_image?template_id=181913649&username=username&password=password&font=arial&boxes=boxes
我相信这应该是 application/x-www-form-urlencoded编码:
params = {
"template_id": 181913649,
"username": "username",
"password": "password",
"font": "arial",
"boxes[0][text]": "top",
"boxes[0][color]": "#ffffff",
"boxes[1][text]": "bottom",
"boxes[1][color]": "#ffffff",
}
所以你应该也可以使用 data (data=params
) 参数代替。
关于python - 将 'boxes' 与 imgflip 的 API 一起使用时出现错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66807028/