google cloud storage client library - behind proxy - access bucket objects using python code?

后端 未结 2 829
误落风尘
误落风尘 2021-01-21 13:42

Centos Linux on vmware - gsutil is working but I am trying to download objects from google cloud storage using python code. Running below python code fails as I am behind a prox

2条回答
  •  不知归路
    2021-01-21 14:19

    Although, google-cloud python library does not have support for proxies directly, it honors HTTPS_PROXY environment variable if set.

    Either:

    export HTTPS_PROXY=https://mycustomproxy.example.com:12345
    python your_python_script.py
    

    Or:

    export https_proxy=https://mycustomproxy.example.com:12345
    python your_python_script.py
    

    You could also set this directly within your python script too (preferably at the very beginning):

    import os
    os.environ['https_proxy'] = 'https://mycustomproxy.example.com:12345'
    
    from google.cloud import storage
    storage_client = storage.Client()
    bucket = storage_client.get_bucket('my-bucket')
    blobs=bucket.list_blobs()
    

    BTW, https_proxy is supported in the urllib module and hence any libraries (like google-cloud here) using urllib can transparently use the proxies for the requests.

提交回复
热议问题