I have a bot that checks gmail for new messages and sends me notifications with their text to telegram. My app is hosted on google cloud and it is running in test mode. According to this answer, OAuth token will expire after 1 week. I tried all suggestions mentioned in that answer, but none helped. I just want to run my app on a server.
I tried to create a new token, but when I use them, I get this error:
oauthlib.oauth2.rfc6749.errors.MismatchingStateError: (mismatching_state) CSRF Warning! State not equal in request and response.
My request code:
creds = None
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', self.SCOPES)
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', self.SCOPES)
creds = flow.run_local_server(port=0)
with open('token.json', 'w') as token:
token.write(creds.to_json())
service = build('gmail', 'v1', credentials=creds)
try:
# Do my stuff
text = self.__get_new_msgs_text(service, 'me')
return text
except NotFindException:
raise NotFindException()