I want to create gcp storage client basically
from google.cloud import storage
# Initialise a client
storage_client = storage.Client()
I am aware that we can set the envar for https_proxy and have the client use the same to access internet behind a protected machine.
I am however not able to set that envar globally in my code due to the design constraints and will need the storage client to use a proxy, there is a param for this _http, which can be used to create a custom session and therefore has its own proxy, I am using the following code to do the same.
from google.auth import transport
from google.cloud import storage
import google.auth
creds, project = google.auth.default()
sess = transport.requests.AuthorizedSession(credentials=creds)
proxies = {"https": "http://iamreplaced.proxy.com:80"}
sess.proxies.update(proxies)
client = storage.Client(_http=sess)
client.get_bucket("my-bucket-name")
I am not able to get it to work as this code times out meaning its not using the proxies that are set through this code. But if I set the global envar everything works without hassle meaning that the proxy itself is working just fine.
If you have worked on something on this side, can you pl point to what I am doing wrong?