HTTPERROR 403 “Insuficiente permision” [closed]

Multi tool use
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
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
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
add a comment |
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
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
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
add a comment |
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
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
python google-api gmail-api google-api-python-client
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
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
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
Insuficiente permision can mean one of two things
- the user you are authncated with does not have permission to do what you are trying to do.
- 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.
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Insuficiente permision can mean one of two things
- the user you are authncated with does not have permission to do what you are trying to do.
- 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.
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
add a comment |
Insuficiente permision can mean one of two things
- the user you are authncated with does not have permission to do what you are trying to do.
- 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.
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
add a comment |
Insuficiente permision can mean one of two things
- the user you are authncated with does not have permission to do what you are trying to do.
- 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.
Insuficiente permision can mean one of two things
- the user you are authncated with does not have permission to do what you are trying to do.
- 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.
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
add a comment |
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
add a comment |
3c98e5oFkpKR0oZ,HwN7R2JnsnTvBTjJwtD263DaH,rSGsF6b9ssItpD,kGV9MCz8,vSE2uyJXk,D1qI cW
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