Is possible to save a temporaly file in a Azure Function Linux Consuption Plan in Python?(是否可以在 Python 中的 Azure Function Linux 消耗计划中保存临时文件?)
问题描述
首先对不起我的英语.我有一个使用 Python 的 Azure Function Linux 消耗计划,我需要生成一个 html,使用 wkhtmltopdf 转换为 pdf 并通过电子邮件发送.
first of all sorry for my English. I have an Azure Function Linux Consuption Plan using Python and I need to generate an html, transform to pdf using wkhtmltopdf and send it by email.
#generate temporally pdf
config = pdfkit.configuration(wkhtmltopdf="binary/wkhtmltopdf")
pdfkit.from_string(pdf_content, 'report.pdf',configuration=config, options={})
#read pdf and transform to Bytes
with open('report.pdf', 'rb') as f:
data = f.read()
#encode bytes
encoded = base64.b64encode(data).decode()
#Send Email
EmailSendData.sendEmail(html_content,encoded,spanish_month)
代码在我的本地开发中运行正常,但是当我部署函数并执行代码时,我收到一条错误消息:
Code is running ok in my local development but when I deploy the function and execute the code I am getting an error saying:
Result: Failure Exception: OSError: wkhtmltopdf reported an error: Loading pages (1/6) [> ] 0% [======> ] 10% [==============================> ] 50% [============================================================] 100% QPainter::begin(): Returned false Error: Unable to write to destination
我认为报告错误是因为出于任何原因写权限不可用.你能帮我解决这个问题吗?
I think that error is reported because for any reason write permission is not available. Can you help me to solve this problem?
提前致谢.
推荐答案
tempfile.gettempdir()
方法返回一个临时文件夹,在Linux上是/tmp代码>
.您的应用程序可以使用此目录来存储临时文件由您的函数在执行期间生成和使用.
The tempfile.gettempdir()
method returns a temporary folder, which on Linux is /tmp
. Your application can use this directory to store temporary files generated and used by your functions during execution.
所以使用/tmp/report.pdf
作为文件目录来保存临时文件.
So use /tmp/report.pdf
as the file directory to save temporary file.
with open('/tmp/report.pdf', 'rb') as f:
data = f.read()
有关更多详细信息,您可以参考此 文章.
For more details, you could refer to this article.
这篇关于是否可以在 Python 中的 Azure Function Linux 消耗计划中保存临时文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以在 Python 中的 Azure Function Linux 消耗计划中保存临时文件?


基础教程推荐
- 筛选NumPy数组 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01