0

I am working with OAuth, for logging into Gmail account and sending emails via python script. I have downloaded client_secret.json file, The file is stored inside C:\Users\anuj.masand\ (Home folder). While running Python script I am getting following error:

oauth2client.clientsecrets.InvalidClientSecretsError: ('Error opening file', 'client_secret.json', 'No such file or directory', 2)

I can see that the file is not available where the script needs it to be. I have read clientsecrets.py file and got to know following code loads the file.

def _loadfile(filename):
try:
    with open(filename, 'r') as fp:
        obj = json.load(fp)
except IOError as exc:
    raise InvalidClientSecretsError('Error opening file', exc.filename,
                                    exc.strerror, exc.errno)
return _validate_clientsecrets(obj)

My code is jumping right into exception part. My question is where to store client_secret.json file? so that interpreter can find the file and moves forward. Where does python really looks for this file?

Reference: Script

Anuj Masand
  • 359
  • 1
  • 4
  • 16

1 Answers1

2

According to this quickstart guide, you are to move the downloaded file to your working directory. With the file named as credentials.json, the guide implemented the file reading as:

# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
    flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
    creds = tools.run_flow(flow, store)
service = build('gmail', 'v1', http=creds.authorize(Http()))

Do ensure that the filenames completely match.

Jacque
  • 757
  • 4
  • 9
  • Thanks @jacque for reverting and for your time, i have figured it out. Instead of passing the file name i did pass the full path(where ever you save your file), it worked.Answer to my question is still away. Thanks anyway. – Anuj Masand Nov 22 '18 at 09:44