pythonanwhere[Errno 2]没有这样的文件或目录:'My项目xxxxxxxxx.json'

2024-05-17 15:20:58 发布

您现在位置:Python中文网/ 问答频道 /正文

I deploied a web app on pythonanywhere but I got this error from view.py.I tried to change SECRETS_FILE = "absolute path" but it still couldn't find .json.Does anyone who had met this error before and solved it?

from __future__ import print_function
from django.shortcuts import render
from datetime import datetime
from django.http import HttpResponse
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pandas as pd
import json
import sys
import os
#import c3pyo as c3

# Create your views here.
def welcome(request):
    return render(request, 'index.html')


def questionnaire(request):
    print("Current folder: " + os.getcwd())
    SCOPE = ["https://spreadsheets.google.com/feeds"]
    SECRETS_FILE ="My Project-XXXXXXXXX.json"
    SPREADSHEET = "BackHarbor"

    credentials = ServiceAccountCredentials.from_json_keyfile_name(SECRETS_FILE, scopes=SCOPE)
    gc = gspread.authorize(credentials)
    workbook = gc.open(SPREADSHEET)
    # Get the first sheet
    sheet = workbook.sheet1
    data = pd.DataFrame(sheet.get_all_records())

error message

^{pr2}$

Tags: djangofromimportjsondatetimerequestiterror
1条回答
网友
1楼 · 发布于 2024-05-17 15:20:58

无法访问您的文件“我的项目”-XXXXXXXXX.json在

尝试从“我的项目”重命名此文件-XXXXXXXXX.json“到”我的项目-XXXXXXXXX.json'

或者这可能有用我不知道

可以在空格前添加反斜杠

SECRETS_FILE ="My\ Project-XXXXXXXXX.json"

相关问题 更多 >