google-api-python-client
google-api-python-client copied to clipboard
GMail API with Apigee proxy
Hi, I need to have my connection to google API run through my Apigee proxy but I am having some issues. This is my code I am using to set up.
import httplib2
import google_auth_httplib2
from httplib2 import socks
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
SCOPES = [
"https://www.googleapis.com/auth/gmail.modify",
"https://www.googleapis.com/auth/gmail.compose",
"https://www.googleapis.com/auth/gmail.send",
"https://www.googleapis.com/auth/gmail.labels",
"https://www.googleapis.com/auth/gmail.readonly"
]
PATHS = {
"credentials" : os.path.join(os.path.dirname(__file__), "credentials.json"),
"token" : os.path.join(os.path.dirname(__file__), "token.json")
}
PROXY_URL = "<my-domain-url>"
PROXY_PORT = 9107
http = httplib2.Http(proxy_info=httplib2.ProxyInfo(
socks.PROXY_TYPE_HTTP, PROXY_URL, PROXY_PORT
))
credentials = Credentials.from_authorized_user_file(PATHS['token'], SCOPES)
authorized_http = google_auth_httplib2.AuthorizedHttp(credentials, http=http)
service = build("gmail", "v1", http=authorized_http)
results = service.users().messages().list(userId='me').execute()
messages = results.get('messages', [])
So, I am getting this error:
_orgsocket.connect(self, (self.__proxy[1], portnum))
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
When I change to the correct proxy url,
raise exceptions.TransportError(exc)
google.auth.exceptions.TransportError: Unable to find the server at oauth2.googleapis.com