python - 为什么我不能从 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 写入该文件吗?
解决方案
我发现如果我以 root 身份运行脚本,文件就会被写入,所以我将它安排在 root crontab 中,它工作正常。
我仍然想了解为什么在更改文件的所有权限和所有权后它不起作用。
推荐阅读
- c++ - C++中的协议栈和销毁顺序
- php - 如何使用 php 从 playstore 下载 apk?
- php - Laravel 6.4.1 SQLSTATE[HY000] [2002] 连接被拒绝
- java - Hazelcast 存储大型对象导致高延迟问题
- c - 以太网控制器中的硬件 Rx/Tx 队列是什么
- html - 具有滚动和绝对位置的 CSS 粘性表格标题
- json - ambari 蓝图安装失败 - 配置类型未在堆栈中定义
- amazon-web-services - Cloudwatch 代理未将日志发送到 cloudwatch
- jenkins - 詹金斯从传递的参数中删除密码
- javascript - 如何为我的应用程序中需要它的所有 React 组件提供窗口宽度?