Python Filenotfounderror: [errno 2] No Such File Or Directory
I have the following snippet from a script credentials = ServiceAccountCredentials.from_json_keyfile_name('tok.json', ['https://www.googleapis.com/auth/analytics.readonly']) This
Solution 1:
I had this same error. I found out that if I cd into the directory before running the program it runs fine. But obviously, that's not something you'd want to manually do every time. So, I adjusted the file.json to include the absolute path to the file. In other words:
Instead of:
'tok.json'
I changed it to:
'user/folder/tok.json'
I'm not sure if this is the best way to go about it since it will break if you ever move the files to a new directory, but it worked for me.
I think the problem is that when the program runs it's looking in whatever folder the terminal/server is currently in, not necessarily in the program's folder. So you have to explicitly tell it where to go.
Post a Comment for "Python Filenotfounderror: [errno 2] No Such File Or Directory"