Python使用解码的request.content发送pdf文件

Python使用解码的request.content发送pdf文件,python,flask,sendfile,x-sendfile,Python,Flask,Sendfile,X Sendfile,在flask应用程序中,我很难从sharepoint服务器下载文件 我正在向sharepoint api发出获取文件的请求,当我打印下载对象时,它看起来很成功 但我不知道如何解码内容,然后发送下载 我试过下面的方法 return send_file(BytesIO(download.content), mimetype='application/pdf', as_attachment=True, attachment_filename='test.pdf') 但当我试图打开它时,它似乎没有正

在flask应用程序中,我很难从sharepoint服务器下载文件

我正在向sharepoint api发出获取文件的请求,当我打印下载对象时,它看起来很成功

但我不知道如何解码内容,然后发送下载

我试过下面的方法

return send_file(BytesIO(download.content), mimetype='application/pdf', as_attachment=True, attachment_filename='test.pdf')
但当我试图打开它时,它似乎没有正确解码


如果您使用
请求
模块和快捷方式
get
发出get请求,只需返回内容以及状态代码和标题即可

return download.content, download.status_code, download.headers.items()

如果您使用
requests
模块和快捷方式
get
发出get请求,只需返回内容以及状态代码和标题即可

return download.content, download.status_code, download.headers.items()

这回答了你的问题吗?您能否共享向sharepoint api发出请求的代码?这是否回答了您的问题?你能分享你向sharepoint api发出请求的代码吗?哇,它成功了。我发誓我试过这个组合!小问题现在知道如何强制弹出窗口文件名了吗?是否与“内容处置”有关:“附件”,完美
download.headers['Content-Disposition']=f'attachment;filename={file_name}'
wow,它成功了。我发誓我试过这个组合!小问题现在知道如何强制弹出窗口文件名了吗?是否与“内容处置”有关:“附件”,完美
download.headers['Content-Disposition']=f'attachment;文件名={file_name}'