Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quickstart.py fails on error: No such file or directory: 'credentials.json' #134

Open
ghost opened this issue Nov 28, 2019 · 18 comments
Open
Assignees

Comments

@ghost
Copy link

ghost commented Nov 28, 2019

Expected Behavior

Browser window should open requesting authorisation

Actual Behavior

No browser opens. Error logged to console:
$ python quickstart.py
Traceback (most recent call last):
File "quickstart.py", line 52, in
main()
File "quickstart.py", line 29, in main
'credentials.json', SCOPES)
File "/home/iarla/civetweb-instance-cal/cal/local/lib/python2.7/site-packages/google_auth_oauthlib/flow.py", line 196, in from_client_secrets_file
with open(client_secrets_file, 'r') as json_file:
IOError: [Errno 2] No such file or directory: 'credentials.json'

Steps to Reproduce the Problem

  1. run python quickstart.py as instructed in documentation https://developers.google.com/calendar/quickstart/python
  2. Observer no browser appears
  3. Observer error in terminal

Specifications

  • Python version: 2.7.12
  • OS : Linux
  • google-auth-oauthlib version: 0.4.1
@sqrrrl
Copy link
Member

sqrrrl commented Dec 3, 2019

Did you complete step 1 correctly and save the file as instructed?

@sqrrrl sqrrrl self-assigned this Dec 3, 2019
@darrenlimweiyang
Copy link

@tenleftfingers It seems like you did not add the credentials.json file into working directory as instructed?

@ghost
Copy link
Author

ghost commented Jan 11, 2020 via email

@Devarsh-leo
Copy link

i am also facing the same issue when i developed a python script it worked and now i am opening it after few months it is showing:
FileNotFoundError: [Errno 2] No such file or directory: 'credentials.json'

is there anyway to regenerate the credential ?

@Devarsh-leo
Copy link

[solved] I provided full path of credential and it worked. i guess my editor has parent folder of my project as its main folder.

@shewitt-au
Copy link

I am also having this issue. The first comment in this ticket says the following:
"Did you complete step 1 correctly and save the file as instructed?"

Step one is "To install the Google client library for Python". I see no instructions to save a file.
Am I missing something here?

@rhadad
Copy link

rhadad commented Apr 28, 2021

I was having the same problem. It looks like it's in the Prerequisites step now. On the Python Quickstart instructions page, https://developers.google.com/sheets/api/quickstart/python?authuser=3:

Underneath the note box that reads, "Note: For this quickstart, you are enabling the 'Google Sheets API'." is a bullet point that reads, "Authorization credentials for a desktop application. To create credentials for a desktop application, refer to Create credentials." With a link on the last two words, "Create credentials." This will take you to another page with some instructions that will eventually create the JSON file. Be sure to rename the file once it's downloaded to credentials.json.

@xutiann
Copy link

xutiann commented Apr 29, 2021

I'm having the same problem and I already rename the json file to credentials.json but it still shows the error. Can anyone advise me what I should do?

@rhadad
Copy link

rhadad commented Apr 29, 2021

It sounds like the computer can't find it, so it's likely in the wrong folder. Make sure it's in the working directory or that you change the filepath to wherever it's saved on your computer.

@xutiann
Copy link

xutiann commented Apr 29, 2021

How do know where is my working directory?

@antoineneidecker
Copy link

@github-canadianlad
Copy link

Alright, I figured it out. You need to jump a few hoops to download the JSON file (Remember to rename it to credentials.json)

  1. Go to this link https://console.cloud.google.com/
  2. Create credential from

I was having the same problem. It looks like it's in the Prerequisites step now. On the Python Quickstart instructions page, https://developers.google.com/sheets/api/quickstart/python?authuser=3:

Underneath the note box that reads, "Note: For this quickstart, you are enabling the 'Google Sheets API'." is a bullet point that reads, "Authorization credentials for a desktop application. To create credentials for a desktop application, refer to Create credentials." With a link on the last two words, "Create credentials." This will take you to another page with some instructions that will eventually create the JSON file. Be sure to rename the file once it's downloaded to credentials.json.

Follows this guy's step

@maxloosmu
Copy link

maxloosmu commented Oct 24, 2021

I'm running pip and python from the Anaconda Prompt on my Windows 10 PC. I've 2 Google Drives running on virtual drives G and H. I've done Step 1 and 2 from https://developers.google.com/apps-script/api/quickstart/python.

When I got to Step 3, I got this error:

(base) C:\Users\Max\Downloads>python quickstart.py
Traceback (most recent call last):
  File "quickstart.py", line 81, in <module>
    main()
  File "quickstart.py", line 45, in main
    'credentials.json', SCOPES)
  File "C:\Users\Max\anaconda3\lib\site-packages\google_auth_oauthlib\flow.py", line 201, in from_client_secrets_file
    with open(client_secrets_file, "r") as json_file:
FileNotFoundError: [Errno 2] No such file or directory: 'credentials.json'

In the quickstart.py file, I've tried changing this:

flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)

To this:

flow = InstalledAppFlow.from_client_secrets_file('C:\Users\Max\Downloads\credentials.json', SCOPES)

And to this:

flow = InstalledAppFlow.from_client_secrets_file('G:\My Drive\Google Sheets\credentials.json', SCOPES)

I've a copy of credentials.json at both locations, but both didn't work. I've tried setting the Windows Path variable to include G:\My Drive\Google Sheets, but that didn't work either. I also did this from the command prompt based on these instructions: https://cloud.google.com/docs/authentication/getting-started#windows.

set GOOGLE_APPLICATION_CREDENTIALS="G:\My Drive\Google Sheets\credentials.json"

But that didn't work too.

I then tried the same steps with new credentials.json and quickstart.py based on instructions from: https://developers.google.com/sheets/api/quickstart/python.

I got a similar error:

(base) G:\My Drive\Google Sheets>python quickstart.py
Traceback (most recent call last):
  File "quickstart.py", line 54, in <module>
    main()
  File "quickstart.py", line 31, in main
    'credentials.json', SCOPES)
  File "C:\Users\Max\anaconda3\lib\site-packages\google_auth_oauthlib\flow.py", line 201, in from_client_secrets_file
    with open(client_secrets_file, "r") as json_file:
FileNotFoundError: [Errno 2] No such file or directory: 'credentials.json'

Does anyone know how to resolve this? Is there a way to set the working directory?

@maxloosmu
Copy link

My problem has been resolved. It arised from a typo in the filename of the json file. I had mistakenly added an extra json to the filename, thereby causing the error: credentials.json.json.

@GaoxieNju
Copy link

image
download the file and rename

@biduradhikari
Copy link

biduradhikari commented Feb 1, 2022

Rather than hard coding the path names (which change if you copy the file elsewhere), you should try getting the current directory path. Changing the code from line 31 as follows should solve the issue.

CURR_DIR = os.path.dirname(os.path.realpath(__file__)) print(CURR_DIR) credential_file=str(CURR_DIR)+'/credentials.json' flow = InstalledAppFlow.from_client_secrets_file( credential_file, SCOPES)

@Aran77
Copy link

Aran77 commented Jan 11, 2023

if you rename the file to Credentials.json in windows you will find the name will be credentials.json.json in the cli window.
rename the file to credentials.json in cli.

@MartianTribe
Copy link

I resolved this by simply pointing to the full path for the file:

credsPath = os.path.expanduser("~/Desktop/Kargo/Development/Python/KargoPy/modules/credentials.json")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests