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

后端 未结 2 827
误落风尘
误落风尘 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:07

    The google-cloud python library doesn't have support for proxies. gsutil's proxy support comes from its use of the boto library, so you might consider using that library if you need proxy support.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题