I know I can use google-auth
library but it does not support Python 2.7, so I need to use oauth2client. I have the following working code using google-auth
:
credentials = service_account.Credentials.from_service_account_info(serviceAccountJSON, scopes=[url])
session = requests.session()
session.verify = None
session.proxies.update(p)
credentials.refresh(google.auth.transport.requests.Request(session))
return credentials.token
But when I replicate the same thing using oauth2client
:
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
import requests
def get_token(serviceAccountPath, authTarget, proxy_url, proxy_port):
credentials = ServiceAccountCredentials.from_json_keyfile_name(
serviceAccountPath, scopes=[authTarget]
)
http_auth = credentials.authorize(httplib2.Http(proxy_info=httplib2.ProxyInfo(
httplib2.socks.PROXY_TYPE_HTTP,
proxy_url,
proxy_port
), disable_ssl_certificate_validation=True))
credentials.refresh(http_auth.request)
return credentials.access_token
I got the error: cannot set verify_mode to CERT_NONE when check_hostname is enable
. How can I fix it? It is the same logic but somehow the second one gives an error.
Or: Is there an alternative way to obtain GCP auth token(bearer) in Python 2.7?