Python 中是否有用于从 Smartsheets 中提取附件的函数?

问题描述 投票:0回答:1

我正在尝试从 Smartsheets API 中提取信息——我可以成功获取单元格和列标题的值。我没有为网站使用 SDK,因为它无法正常工作。 有些行上有附件,我想下载它们并保存到我的电脑上。在我访问“行”键后,“附件”看起来应该是一个键值,但出现错误,提示“附件”不是键。 如何在不使用 SDK 的情况下连续访问附件?

d 在范围内(n_rows): 打印(数据['行'][d]['附件']

python smartsheet-api
1个回答
0
投票

我同意 Kim 的观点,“使用 SDK 将为您节省很多时间。”

关于您的问题,您可能没有指定包含附件。

参数 = { '包括':'附件' }

response = requests.get('https://api.smartsheet.com/2.0/sheets/{sheetId}}', params=params, headers=headers)

或者如果你使用SDK,

sheet = smartsheet_client.Sheets.get_sheet( sheet_id, include = '附件')

或者您可以使用列表附件方法。

response=requests.get('https://api.smartsheet.com/2.0/sheets/{sheetId}/attachments', headers=headers)

无论哪种方式,要下载附件,您都需要获得“attachmentId”。

然后,通过“attachmentId”,使用获取附件方法“获取允许您下载附件的临时 URL。”

response = requests.get('https://api.smartsheet.com/2.0/sheets/{sheetId}/attachments/{attachmentId}', headers=headers)

或者如果你使用SDK,

附件 = smartsheet_client.Attachments.get_attachment(

9283173393803140,#sheet_id

4583173393803140) # attachment_id

© www.soinside.com 2019 - 2024. All rights reserved.