【发布时间】:2020-01-25 15:29:07
【问题描述】:
我有一个烧瓶应用程序,它使用 json 文件来存储一些配置数据。该 .json 文件存储在与烧瓶应用程序文件(app.py)所在的位置(目录)相同的位置(目录)。这个烧瓶应用程序在本地机器上运行良好。但是当我部署到实时服务器(Ubuntu VPS)时,我收到了一个 WSGI 错误提示
FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
我的 .json 文件代码如下
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
import json
import random
with open('config.json', 'r') as c:
par = json.load(c)["par"]
这是什么问题以及如何解决?
【问题讨论】:
-
您确定将 json 文件与其他文件一起部署了吗?试试
print(os.listdir('.'))看看你在哪里 -
服务器可以在不同的文件夹中运行它,作为不同的用户,具有不同的权限——大多数是出于安全原因。您可能需要使用文件的完整路径。
-
我试过这个。但同样的问题。 json_data = os.path.join('config.json') with open(json_data, 'r') as c: par = json.load(c)["par"]
标签: python json flask ubuntu-18.04