Jerrod
Jerrod

Reputation: 125

Django not recognizing or seeing JSON file

I've been working on trying to integrate google sheets with django, i'm trying to use gspread. I can see the data using python filename.py, but when I run python manage.py runserver, I keep getting this error:

IOError: [Errno 2] No such file or directory: 'key.json'

It's not recognizing for seeing my json file for some reason, i've also tried using 'key' without the .json, no luck. I've been googling here, any ideas here? Here's my code below

*************************** code below *******************************

import gspread
import json
from oauth2client.service_account import ServiceAccountCredentials
import os

scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('key.json', scope)

gc = gspread.authorize(credentials)
wks = gc.open("RAMP - Master").sheet1
print wks

cell_list = wks.range('A1:B7')
print cell_list

Upvotes: 1

Views: 1535

Answers (1)

thebjorn
thebjorn

Reputation: 27311

If key.json is in the same directory as the file you're running, then the correct syntax is:

import os
DIRNAME = os.path.dirname(__file__)
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    os.path.join(DIRNAME, 'key.json'),
    scope
)

Upvotes: 7

Related Questions