HTTPERROR 403 “Insuficiente permision” [closed]



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to request the users gmail data list messages and modify one of them. i am getting the following error




HTTPERROR 403 “Insuficiente permision”




code



def main():
"""Shows basic usage of the Gmail API.
Lists the user's Gmail labels.
"""
# 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()))

# Call the Gmail API
results = service.users().labels().list(userId='me').execute()
labels = results.get('labels', )

if not labels:
print('No labels found.')
else:
print('Labels:')
for label in labels:
print(label['name'])
response = service.users().messages().list(userId='me',
labelIds='INBOX').execute()
messages =
if 'messages' in response:
messages.extend(response['messages'])
#print(messages)
for i in messages:
aux_id = i
id = aux_id.get('id')
print(id)
message = service.users().messages().get(userId='me', id=id).execute()
#print (type(message))
data = message.get('payload', ).get('body',).get('data')
data = data.decode('base64')
list_of_dic = message.get('payload',).get('headers')
#print(list_of_dic)
#DATE, JUST NEED TO FORMAT IT TO YYYY/MM/DD
for i in list_of_dic:
if i['name'] == 'Date':
aux_date = i
if i['name'] == 'From':
aux_sender = i
if i['name'] == 'Subject':
aux_subject = i
sender = aux_sender.get('value')
date = aux_date.get('value')
subject = aux_subject.get('value')
print(date)
print(sender)
print(subject)
print(data)## data from emaail working
print('***************************************************')
message = service.users().messages().modify(userId='me', id=id,
body='INBOX').execute()









share|improve this question















closed as off-topic by Klaus D., Adriaan, Pearly Spencer, sideshowbarker, ewolden Nov 16 '18 at 8:29


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Klaus D., Adriaan, Pearly Spencer, sideshowbarker, ewolden
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • Could you add trace log of this error?

    – artona
    Nov 15 '18 at 8:55











  • Welcome to Stack Overflow. To ask a good question, it takes more than just copy / pasting your code and error message. Please read How do I ask a good question and improve your question.

    – Klaus D.
    Nov 15 '18 at 8:57












  • @KlausD. I have edited his question i hope this enough information to make the issue clear to you. By reading the code i was able to understand the problem but i have added text to make it more clear.

    – DaImTo
    Nov 15 '18 at 9:01

















0















I am trying to request the users gmail data list messages and modify one of them. i am getting the following error




HTTPERROR 403 “Insuficiente permision”




code



def main():
"""Shows basic usage of the Gmail API.
Lists the user's Gmail labels.
"""
# 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()))

# Call the Gmail API
results = service.users().labels().list(userId='me').execute()
labels = results.get('labels', )

if not labels:
print('No labels found.')
else:
print('Labels:')
for label in labels:
print(label['name'])
response = service.users().messages().list(userId='me',
labelIds='INBOX').execute()
messages =
if 'messages' in response:
messages.extend(response['messages'])
#print(messages)
for i in messages:
aux_id = i
id = aux_id.get('id')
print(id)
message = service.users().messages().get(userId='me', id=id).execute()
#print (type(message))
data = message.get('payload', ).get('body',).get('data')
data = data.decode('base64')
list_of_dic = message.get('payload',).get('headers')
#print(list_of_dic)
#DATE, JUST NEED TO FORMAT IT TO YYYY/MM/DD
for i in list_of_dic:
if i['name'] == 'Date':
aux_date = i
if i['name'] == 'From':
aux_sender = i
if i['name'] == 'Subject':
aux_subject = i
sender = aux_sender.get('value')
date = aux_date.get('value')
subject = aux_subject.get('value')
print(date)
print(sender)
print(subject)
print(data)## data from emaail working
print('***************************************************')
message = service.users().messages().modify(userId='me', id=id,
body='INBOX').execute()









share|improve this question















closed as off-topic by Klaus D., Adriaan, Pearly Spencer, sideshowbarker, ewolden Nov 16 '18 at 8:29


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Klaus D., Adriaan, Pearly Spencer, sideshowbarker, ewolden
If this question can be reworded to fit the rules in the help center, please edit the question.
















  • Could you add trace log of this error?

    – artona
    Nov 15 '18 at 8:55











  • Welcome to Stack Overflow. To ask a good question, it takes more than just copy / pasting your code and error message. Please read How do I ask a good question and improve your question.

    – Klaus D.
    Nov 15 '18 at 8:57












  • @KlausD. I have edited his question i hope this enough information to make the issue clear to you. By reading the code i was able to understand the problem but i have added text to make it more clear.

    – DaImTo
    Nov 15 '18 at 9:01













0












0








0








I am trying to request the users gmail data list messages and modify one of them. i am getting the following error




HTTPERROR 403 “Insuficiente permision”




code



def main():
"""Shows basic usage of the Gmail API.
Lists the user's Gmail labels.
"""
# 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()))

# Call the Gmail API
results = service.users().labels().list(userId='me').execute()
labels = results.get('labels', )

if not labels:
print('No labels found.')
else:
print('Labels:')
for label in labels:
print(label['name'])
response = service.users().messages().list(userId='me',
labelIds='INBOX').execute()
messages =
if 'messages' in response:
messages.extend(response['messages'])
#print(messages)
for i in messages:
aux_id = i
id = aux_id.get('id')
print(id)
message = service.users().messages().get(userId='me', id=id).execute()
#print (type(message))
data = message.get('payload', ).get('body',).get('data')
data = data.decode('base64')
list_of_dic = message.get('payload',).get('headers')
#print(list_of_dic)
#DATE, JUST NEED TO FORMAT IT TO YYYY/MM/DD
for i in list_of_dic:
if i['name'] == 'Date':
aux_date = i
if i['name'] == 'From':
aux_sender = i
if i['name'] == 'Subject':
aux_subject = i
sender = aux_sender.get('value')
date = aux_date.get('value')
subject = aux_subject.get('value')
print(date)
print(sender)
print(subject)
print(data)## data from emaail working
print('***************************************************')
message = service.users().messages().modify(userId='me', id=id,
body='INBOX').execute()









share|improve this question
















I am trying to request the users gmail data list messages and modify one of them. i am getting the following error




HTTPERROR 403 “Insuficiente permision”




code



def main():
"""Shows basic usage of the Gmail API.
Lists the user's Gmail labels.
"""
# 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()))

# Call the Gmail API
results = service.users().labels().list(userId='me').execute()
labels = results.get('labels', )

if not labels:
print('No labels found.')
else:
print('Labels:')
for label in labels:
print(label['name'])
response = service.users().messages().list(userId='me',
labelIds='INBOX').execute()
messages =
if 'messages' in response:
messages.extend(response['messages'])
#print(messages)
for i in messages:
aux_id = i
id = aux_id.get('id')
print(id)
message = service.users().messages().get(userId='me', id=id).execute()
#print (type(message))
data = message.get('payload', ).get('body',).get('data')
data = data.decode('base64')
list_of_dic = message.get('payload',).get('headers')
#print(list_of_dic)
#DATE, JUST NEED TO FORMAT IT TO YYYY/MM/DD
for i in list_of_dic:
if i['name'] == 'Date':
aux_date = i
if i['name'] == 'From':
aux_sender = i
if i['name'] == 'Subject':
aux_subject = i
sender = aux_sender.get('value')
date = aux_date.get('value')
subject = aux_subject.get('value')
print(date)
print(sender)
print(subject)
print(data)## data from emaail working
print('***************************************************')
message = service.users().messages().modify(userId='me', id=id,
body='INBOX').execute()






python google-api gmail-api google-api-python-client






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 9:00









DaImTo

47.1k1168249




47.1k1168249










asked Nov 15 '18 at 8:52









joao santanajoao santana

95




95




closed as off-topic by Klaus D., Adriaan, Pearly Spencer, sideshowbarker, ewolden Nov 16 '18 at 8:29


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Klaus D., Adriaan, Pearly Spencer, sideshowbarker, ewolden
If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by Klaus D., Adriaan, Pearly Spencer, sideshowbarker, ewolden Nov 16 '18 at 8:29


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Klaus D., Adriaan, Pearly Spencer, sideshowbarker, ewolden
If this question can be reworded to fit the rules in the help center, please edit the question.












  • Could you add trace log of this error?

    – artona
    Nov 15 '18 at 8:55











  • Welcome to Stack Overflow. To ask a good question, it takes more than just copy / pasting your code and error message. Please read How do I ask a good question and improve your question.

    – Klaus D.
    Nov 15 '18 at 8:57












  • @KlausD. I have edited his question i hope this enough information to make the issue clear to you. By reading the code i was able to understand the problem but i have added text to make it more clear.

    – DaImTo
    Nov 15 '18 at 9:01

















  • Could you add trace log of this error?

    – artona
    Nov 15 '18 at 8:55











  • Welcome to Stack Overflow. To ask a good question, it takes more than just copy / pasting your code and error message. Please read How do I ask a good question and improve your question.

    – Klaus D.
    Nov 15 '18 at 8:57












  • @KlausD. I have edited his question i hope this enough information to make the issue clear to you. By reading the code i was able to understand the problem but i have added text to make it more clear.

    – DaImTo
    Nov 15 '18 at 9:01
















Could you add trace log of this error?

– artona
Nov 15 '18 at 8:55





Could you add trace log of this error?

– artona
Nov 15 '18 at 8:55













Welcome to Stack Overflow. To ask a good question, it takes more than just copy / pasting your code and error message. Please read How do I ask a good question and improve your question.

– Klaus D.
Nov 15 '18 at 8:57






Welcome to Stack Overflow. To ask a good question, it takes more than just copy / pasting your code and error message. Please read How do I ask a good question and improve your question.

– Klaus D.
Nov 15 '18 at 8:57














@KlausD. I have edited his question i hope this enough information to make the issue clear to you. By reading the code i was able to understand the problem but i have added text to make it more clear.

– DaImTo
Nov 15 '18 at 9:01





@KlausD. I have edited his question i hope this enough information to make the issue clear to you. By reading the code i was able to understand the problem but i have added text to make it more clear.

– DaImTo
Nov 15 '18 at 9:01












1 Answer
1






active

oldest

votes


















0














Insuficiente permision can mean one of two things



  1. the user you are authncated with does not have permission to do what you are trying to do.

  2. The user has not granted your application enough permissions to do what you are trying to do.

As you are using user id of me then i think we can assume that the problem is not the first one. A user by default would have access to access their data. The issue is with the scopes of the permissions your application has requested and the user has granted.



messages.list and messages.get require one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

  • https://www.googleapis.com/auth/gmail.readonly

  • https://www.googleapis.com/auth/gmail.metadata

However messages.modify requires one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

You have not mentioned what scopes you have requested. I sugest that you check the scopes and make sure that you have requested enough permissions to modify the email. Make sure that you authenticate the user.



Solution



Check what you have SCOPES set to in this line



flow = client.flow_from_clientsecrets('credentials.json', SCOPES)


make sure to add either



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

Then run the code again so that it asks for the users consent again.






share|improve this answer

























  • thank you DalmTo, but im not sure how i add scopes, is it on the credential files?

    – joao santana
    Nov 15 '18 at 9:01











  • SCOPES <-- that is your scopes. What do you have that variable set to.

    – DaImTo
    Nov 15 '18 at 9:02

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Insuficiente permision can mean one of two things



  1. the user you are authncated with does not have permission to do what you are trying to do.

  2. The user has not granted your application enough permissions to do what you are trying to do.

As you are using user id of me then i think we can assume that the problem is not the first one. A user by default would have access to access their data. The issue is with the scopes of the permissions your application has requested and the user has granted.



messages.list and messages.get require one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

  • https://www.googleapis.com/auth/gmail.readonly

  • https://www.googleapis.com/auth/gmail.metadata

However messages.modify requires one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

You have not mentioned what scopes you have requested. I sugest that you check the scopes and make sure that you have requested enough permissions to modify the email. Make sure that you authenticate the user.



Solution



Check what you have SCOPES set to in this line



flow = client.flow_from_clientsecrets('credentials.json', SCOPES)


make sure to add either



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

Then run the code again so that it asks for the users consent again.






share|improve this answer

























  • thank you DalmTo, but im not sure how i add scopes, is it on the credential files?

    – joao santana
    Nov 15 '18 at 9:01











  • SCOPES <-- that is your scopes. What do you have that variable set to.

    – DaImTo
    Nov 15 '18 at 9:02















0














Insuficiente permision can mean one of two things



  1. the user you are authncated with does not have permission to do what you are trying to do.

  2. The user has not granted your application enough permissions to do what you are trying to do.

As you are using user id of me then i think we can assume that the problem is not the first one. A user by default would have access to access their data. The issue is with the scopes of the permissions your application has requested and the user has granted.



messages.list and messages.get require one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

  • https://www.googleapis.com/auth/gmail.readonly

  • https://www.googleapis.com/auth/gmail.metadata

However messages.modify requires one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

You have not mentioned what scopes you have requested. I sugest that you check the scopes and make sure that you have requested enough permissions to modify the email. Make sure that you authenticate the user.



Solution



Check what you have SCOPES set to in this line



flow = client.flow_from_clientsecrets('credentials.json', SCOPES)


make sure to add either



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

Then run the code again so that it asks for the users consent again.






share|improve this answer

























  • thank you DalmTo, but im not sure how i add scopes, is it on the credential files?

    – joao santana
    Nov 15 '18 at 9:01











  • SCOPES <-- that is your scopes. What do you have that variable set to.

    – DaImTo
    Nov 15 '18 at 9:02













0












0








0







Insuficiente permision can mean one of two things



  1. the user you are authncated with does not have permission to do what you are trying to do.

  2. The user has not granted your application enough permissions to do what you are trying to do.

As you are using user id of me then i think we can assume that the problem is not the first one. A user by default would have access to access their data. The issue is with the scopes of the permissions your application has requested and the user has granted.



messages.list and messages.get require one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

  • https://www.googleapis.com/auth/gmail.readonly

  • https://www.googleapis.com/auth/gmail.metadata

However messages.modify requires one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

You have not mentioned what scopes you have requested. I sugest that you check the scopes and make sure that you have requested enough permissions to modify the email. Make sure that you authenticate the user.



Solution



Check what you have SCOPES set to in this line



flow = client.flow_from_clientsecrets('credentials.json', SCOPES)


make sure to add either



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

Then run the code again so that it asks for the users consent again.






share|improve this answer















Insuficiente permision can mean one of two things



  1. the user you are authncated with does not have permission to do what you are trying to do.

  2. The user has not granted your application enough permissions to do what you are trying to do.

As you are using user id of me then i think we can assume that the problem is not the first one. A user by default would have access to access their data. The issue is with the scopes of the permissions your application has requested and the user has granted.



messages.list and messages.get require one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

  • https://www.googleapis.com/auth/gmail.readonly

  • https://www.googleapis.com/auth/gmail.metadata

However messages.modify requires one of the following scopes to work.



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

You have not mentioned what scopes you have requested. I sugest that you check the scopes and make sure that you have requested enough permissions to modify the email. Make sure that you authenticate the user.



Solution



Check what you have SCOPES set to in this line



flow = client.flow_from_clientsecrets('credentials.json', SCOPES)


make sure to add either



  • https://mail.google.com/

  • https://www.googleapis.com/auth/gmail.modify

Then run the code again so that it asks for the users consent again.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 9:04

























answered Nov 15 '18 at 8:59









DaImToDaImTo

47.1k1168249




47.1k1168249












  • thank you DalmTo, but im not sure how i add scopes, is it on the credential files?

    – joao santana
    Nov 15 '18 at 9:01











  • SCOPES <-- that is your scopes. What do you have that variable set to.

    – DaImTo
    Nov 15 '18 at 9:02

















  • thank you DalmTo, but im not sure how i add scopes, is it on the credential files?

    – joao santana
    Nov 15 '18 at 9:01











  • SCOPES <-- that is your scopes. What do you have that variable set to.

    – DaImTo
    Nov 15 '18 at 9:02
















thank you DalmTo, but im not sure how i add scopes, is it on the credential files?

– joao santana
Nov 15 '18 at 9:01





thank you DalmTo, but im not sure how i add scopes, is it on the credential files?

– joao santana
Nov 15 '18 at 9:01













SCOPES <-- that is your scopes. What do you have that variable set to.

– DaImTo
Nov 15 '18 at 9:02





SCOPES <-- that is your scopes. What do you have that variable set to.

– DaImTo
Nov 15 '18 at 9:02





Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20