Caller does not have permission error when using GMail API - django

I get 500 server error on my django website thats running on Google App Engine. When I look at Google App Engine logs I see the following error:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest returned "The caller does not have permission">
When I hard refresh the browser this error goes away. Then after some time it pops back up. Happens on mobile(firefox, safari), laptop (firefox,chrome).
UPDATE:
In Django settings.py I have following code. Its last line generates the error :
pickle_path = 'token.pickle' # path to token.pickle
with open(pickle_path, 'rb') as token:
creds = pickle.load(token)
SERVICE = build('gmail', 'v1', credentials=creds) # ERROR LINE
When I run the django server locally: I get following error:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest returned "The caller does not have permission">
When I restart cloud sql connection from my terminal - the error is gone. This never used to happen until a few days ago.

Here's a workaround:
Download the discovery_doc directly from google here
Load the json file (you can name it gmail-api.json)
Build from this json file using build_from_document
Before
from googleapiclient.discovery import build
gmail_creds = get_service_account_creds()
gmail_service = build('gmail', 'v1', credentials=gmail_creds)
After
from googleapiclient.discovery import build_from_document
discovery_doc = load_json('config/gmail-api.json')
gmail_creds = get_service_account_creds()
gmail_service = build_from_document(discovery_doc, credentials=gmail_creds)
It seems that it is now a P0 for Google, so hopefully it will be fixed soon.
https://issuetracker.google.com/issues/160441983

I am also started facing this issue. I have been using Google APIs for more than a year, but suddenly this error HttpError 403 when requesting https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest returned "The caller does not have permission. However, couple of times I didn't see this error and API call was successful. I hope this error at the Gmail API server.
Update:
I am able to call Google APIs without any issues. Seems like issue is resolved at google's end.

I am having the same issue with GAM ADV-X. I thought it was an issue on my computer so I tried on 2 different computers and get the same error. It indeed looks like something changed in the Gmail API over the weekend. Will submit a ticket to Google.

Related

django-rest-framework-social-oauth2: error 400 - redirect_uri_mismatch

I've been trying to add google login to my django app following this tutorial:
https://github.com/RealmTeam/django-rest-framework-social-oauth2
By following exactly the instructions, everything works fine in local.
However, when I try to replicate the same on the server, I get the following error on the redirect page of the login:
Error 400: redirect_uri_mismatch
redirect_uri: http://localhost:8000/auth/complete/google-oauth2/
What is strange to me is, in my google developer console, I have set up the correct redirect url in my app, as follows:
https://mydjangoapp.com/auth/complete/google-oauth2/
And I have also put 'mydjangoapp.com' under 'Authorised JavaScript origins'.
So my question is, why google keeps telling me that the redirect url is
http://localhost:8000/auth/complete/google-oauth2/
which is not the one I have set up in the console? Perhaps there is something obvious that I'm missing here. Thank you!
Why google keeps telling me that the redirect url is
Because your application is sending its in your code the app is running on http://localhost:8000 and if you are using a client library its probably adding the rest automatically.
http://localhost:8000/auth/complete/google-oauth2/
The redirect uri must exactly match what you are sending from your application.
You need to add
http://localhost:8000/auth/complete/google-oauth2/
Javascript origin is only needed if your code is using javascript.
This video will show you how to fix the error. Google OAuth2: How the fix redirect_uri_mismatch error. Part 2 server sided web applications.
If you want your code to send https://mydjangoapp.com then your going to have to be running it from https://mydjangoapp.com probably and you may need to figure out how to configure it so that it is running from the correct host.

Django “python-social-auth”: HTTP 403 Client Error with github

I've followed closely this tutorial which is great.
Everything worked fine until today, where when I log with github I get this error:
HTTPError at /oauth/complete/github/
403 Client Error: Forbidden for url: https://github.com/login/oauth/access_token
What am I missing / what could I have changed?
I'm currently developping a Website with social networks login.
Everything works fine (google, facebook and twitter) but not github: after some attempts, I'm getting now a 403.
The problem in Django is that 403 errors dont show the HTML content that come with the error!
I had to run in Debug mode and add a breakpoint in the file
/usr/local/lib/python3.7/site-packages/requests/models.py
line 940 / where there's the code raise HTTPError(http_error_msg, response=self)
Inspecting the variable self.content.decode("utf-8") showed me that I've been restricted (for no logical reason - what's more strange is that the same code, on my same PC but under Windows, works like a charm).
I'm hoping the technical team at github will explain what went wrong...

GAE Error | Server Encountered an Error and couldn't complete your request. Please try again after 30 seconds

We have an app running on Google App Engine with Python 2.7 runtime which can be assessed using Google Login, implemented using users API endpoint.
We are getting an error "Server Encountered an Error and couldn't complete your request. Please try again after 30 seconds" whenever user tries to open the web app.. The error is thworn on App Engine side, since the 500 error happens on that line where this call is made 'GET https://appengine.google.com/_ah/conflogin'.
This happens for both mobile(majorly) and web. It shows the same error when we try after the specified time.
However when we clear the browser cookies, cache, history etc etc it starts working. Not sure why. But we cannot users to clear all such stuffs all time as they might loose the information that they browsed.
We tried various cases for login(multiple login, single login, incognito mode) but couldn't figure the root cause of the problem.
Have anyone faced such issues before? If yes please share how you solved it.

trying to install pcfDev on macbook , get error -Pivotal Network returned: 403 Forbidden

I am trying to install PCF dev and when i put in my API token I get 403 Forbidden error
cf dev start
Less than 4096 MB of free memory detected, continue (y/N): > y
Please retrieve your Pivotal Network API from:
https://network.pivotal.io/users/dashboard/edit-profile
API token>
FAILED
Error: Pivotal Network returned: 403 Forbidden.
I can do >> curl https://network.pivotal.io
without errors
I have cf cli installed
cf version 6.21.1+6fd3c9f-2016-08-10
Also have Oracle Virtual box
5.1.4r110228
please help
i tried a few other things but kept getting the same error. I thought I am typing or copy pasting the wrong api token - when i deliberately typed out a wrong api token to test this theory - i actually got wrong api token error.
Then I had a hunch that there's something wrong with my pivotal account itself, so i created another one with another email id and tried again and it worked..
so that was the problem..

Azure Web Site with Django 500 Error

I've spent over 8 hours trying to get this Django site up and running on an Azure Website. I've nearly thrown in the towel would really appreciate some help.
So far I have tried numerous methods and followed different tutorials, but they have all yielded the same result. Here is the most recent tutorial I have followed: http://www.windowsazure.com/en-us/develop/python/tutorials/web-sites-with-django/
Now that my site is "up", I am seeing a 500 error for all requests. Here is the error in the log:
The page cannot be displayed because an internal server error has occurred.
Most likely causes:
IIS received the request; however, an internal error occurred during
the processing of the request. The root cause of this error depends on which mo
dule handles the request and what was happening in the worker process when this
error occurred. IIS was not able to access the web.config file for t
he Web site or application. This can occur if the NTFS permissions are set incor
rectly. IIS was not able to process configuration for the Web site o
r application. The authenticated user does not have permission to u
se this DLL. The request is mapped to a managed handler but the .
NET Extensibility Feature is not installed.
Things you can try:
Ensure that the NTFS permissions for the web.config file are correct
and allow access to the Web server's machine account. Check the ev
ent logs to see if any additional information was logged. Verify the p
ermissions for the DLL. Install the .NET Extensibility feature if th
e request is mapped to a managed handler. Create a tracing rule to tra
ck failed requests for this HTTP status code. For more information about creatin
g a tracing rule for failed requests, click here.
Please help!
I got it working by settings up a new django project from the azure gallery and changed some configs and such.
Edit: The configs I updated was just the name of my app. In my case I also updated the database config with the database I wanted to use in settings.py.
The lesson learned from this is that it is easier to initialize the app from Azure's "Create from gallery" feature, and then pull down the source and modify it via ftp or git to achieve the desired project structure/naming.