【发布时间】:2017-12-14 12:24:28
【问题描述】:
我在 pythonanywhere 上部署了一个网络应用程序,但我收到了这个错误 view.py.我试图改变 SECRETS_FILE = "absolute path" 但它仍然 找不到.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
【问题讨论】:
-
可能和文件的位置有关;我看到您在这段代码上方打印出
os.getcwd的结果——它打印出的工作目录肯定是包含机密文件的目录吗?
标签: python django-views pythonanywhere