首页 > 解决方案 > 为什么我不能从 Plotly 写入 /var/www/html/index.html?

问题描述

我正在使用 Raspberry Pi Zero W 记录来自 BME280 传感器的数据。我将数据编译到文本文件中,然后使用 Plotly 将其可视化。我想将输出写入 /var/www/html/index.html 以便 Apache 可以在我的网络中提供该图。这是一些非常精简的代码。

import plotly.graph_objs as go
import plotly.offline as offline
import numpy as np

N = 1000
t = np.linspace(0, 10, 100)
y = np.sin(t)

fig = go.Figure(data=go.Scatter(x=t, y=y, mode='markers'))

fig.write_html('/var/www/html/index.html')

这抛出:

PermissionError:[Errno 13] 权限被拒绝:'/var/www/html/index.html'

我已按照本指南中的说明更改 /var/www/html 的权限和所有权。我也尝试过更改文件本身的所有权,但没有成功。有人能告诉我我需要做什么才能从 Python 写入该文件吗?

标签: pythonlinuxapacheraspberry-pi

解决方案


我发现如果我以 root 身份运行脚本,文件就会被写入,所以我将它安排在 root crontab 中,它工作正常。

我仍然想了解为什么在更改文件的所有权限和所有权后它不起作用。


推荐阅读