将“框”与imgflip的API一起使用时出现错误消息

2024-07-03 07:44:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python的请求模块使用imgflip的API“生成一个Meme”,但是在使用boxes时,我收到以下错误消息:

No texts specified. Remember, API request params are http parameters not 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()

我已经将boxes格式化为他们在文档中所说的那样(https://imgflip.com/api) 所以我不知道为什么它不起作用


Tags: 模块notexthttpscomapi消息错误
1条回答
网友
1楼 · 发布于 2024-07-03 07:44:15

当前您正在发送类似以下内容:

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",
}

因此,您还应该能够使用datadata=params)参数

相关问题 更多 >