如何将图像上传到Trello a Trello,但不将其设置为封面(这是默认设置)

2024-09-30 10:39:54 发布

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

我正在使用TrelloAPI将图像上传到Trello卡。Trello默认情况下将图像设置为封面图像。API文档说有一个setCover选项,但我无法让它工作

https://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-attachments-post

def __upload_image_to_card(self, connection: dict, card: dict, image_path : str, cover=False):
    params = (
        ('key', connection['trello_api_key']),
        ('token', connection['trello_api_token']),
    )
    
    values = {
        'file': (image_path, open(image_path, 'rb')),
        'setCover' : (cover),
    }

    # TODO: Move to node_manager
    response = requests.post('https://api.trello.com/1/cards/%s/attachments' % card['id'], params=params, files=values).json()

我试过在布尔值和字符串之间切换,试过去掉括号。我甚至在值中添加了一个错误键,以查看是否可以得到不同的响应。没有阻止上载图像,也没有阻止图像成为默认图像

非常感谢您的帮助


Tags: pathhttps图像imagecomapiidparams
1条回答
网友
1楼 · 发布于 2024-09-30 10:39:54

setCover应该在params中,而不是在files/values中。您可能还需要将其设置为str(cover).lower(),因为它期望的是true/false,而不是True/False

# since you using a list of tuples:
params = (
    ('key', connection['trello_api_key']),
    ('token', connection['trello_api_token']),
    ('setCover', cover),
)

或者作为一句格言:

params = {
    'key': connection['trello_api_key'],
    'token': connection['trello_api_token'],
    'setCover': cover,
}

相关问题 更多 >

    热门问题