Jump to content

Python: How to project folder (cant find .json file) [Errno 2]

Imbellis

Here's the error message:

File "C:\Users\Username\AppData\Local\atom\app-1.24.0\spreadsheet.py", line 6, in <module>
    creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
  File "C:\Program Files\Python\lib\site-packages\oauth2client\service_account.py", line 219, in from_json_keyfile_name
    with open(filename, 'r') as file_obj:
FileNotFoundError: [Errno 2] No such file or directory: 'client_secret.json'

I'd guess that it has something to do with my project folder not really working, but All of the scripts/data are grouped together in a folder.

Here's the code I copied over - seems to be working fine by it's self. It's meant to access data from a google sheet. Eventually, I'll hook this up to a neural net to guestimate results.

So I guess my real question is: How do I properly set up a project folder? (I'm currently using Atom as my text editor.)

 

import gspread
from oauth2client.service_account import ServiceAccountCredentials

# use creds to create a client to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)

# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("kryptos").Sheet1

# Extract and print all of the values
list_of_hashes = sheet.get_all_records()
print(list_of_hashes)

And here's the .json with sensitive data replaced

  "type": "service_account",
  "project_id": "RandomExample-203322",
  "private_key_id": "ohboyilovepickles42069",
  "private_key": "-----BEGIN PRIVATE KEY-----\naeriioaerhoaerjioaerjiogdgmkmnjaerargioioorgjioaerg893489j4gn89a3gauio4ghabn34n9t9494u9g0wkwgu9aseg5uhaeb5hub5hsu5husr5hu5us5usv5uhv5huv5hu,5hbu,b5hsu,sb5hu,sb5hu,osvb5hu,osb5hu,osv,osv5yiosb5hiojsvbshioshiojrthsji,srtbhsrbh,tj,osbhjiostbhjiosrtbhsrtvbhjiosrtvbhsrtbhiosrtbhiosrtbhjiosrtbhjiosbsrbiorortbhiosbrhshioiorjiostbhsbhbh.ibh,bsmiosrtbhiosrtjmiosrjiothrandomtext=\n-----END PRIVATE KEY-----\n",
  "client_email": "codesolverilluminati.gserviceaccount.com",
  "client_id": "1357902468",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://accounts.google.com/o/oauth2/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/here'ssomemorehiddendata.iam.gserviceaccount.com"
}

I'm sorry if the data is needed to find out what's wrong, but I'm unable to see any reason it would.

Thanks for the help.

Fan Comparisons          F@H          PCPartPicker         Analysis of Market Trends (Coming soon? Never? Who knows!)

Designing a mITX case. Working on aluminum prototypes.

Open for intern / part-time. Good at maths, CAD and airflow stuff. Dabbled with Python.

Please fill out this form! It helps a ton! https://linustechtips.com/main/topic/841400-the-poll-to-end-all-polls-poll/

Link to comment
Share on other sites

Link to post
Share on other sites

try this:

basedir = os.path.abspath(os.path.dirname(__file__))
data_json = basedir+'client_secret.json'
creds = ServiceAccoutCredential.from_json_keyfile_name(data_json, scope)

this usually works for me

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×