我在pythonanywhere上展示了一个web应用程序,但是我收到了这个错误 view.py.I试图更改SECRETS_FILE ="绝对路径"但它仍然 无法找到.json。之前和之前遇到此错误的人 解决了吗?
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())
错误消息
FileNotFoundError at /result
[Errno 2] No such file or directory: 'My Project-XXXXXXXXX.json'
Request Method: GET
Request URL: http://yujing.pythonanywhere.com/result
Django Version: 1.8.18
Exception Type: FileNotFoundError
Exception Value:
[Errno 2] No such file or directory: 'My Project-XXXXXXXX.json'
Exception Location: /home/YuJing/django_project_venv/lib/python3.5/site-packages/oauth2client/service_account.py in from_json_keyfile_name, line 219
答案 0 :(得分:0)
无法访问您的文件My Project-XXXXXXXXX.json
尝试将此文件从“我的项目-XXXXXXXXX.json”重命名为“MyPoject-XXXXXXXXX.json”
或者这可能有效我不知道
您可以在空格
之前添加反斜杠 SECRETS_FILE ="My\ Project-XXXXXXXXX.json"