vmware上的Centos Linux - gsutil正在工作,但我试图使用python代码从谷歌云存储中下载对象。在代理服务器后面运行下面的python代码失败。我尝试导出http_proxy和https_proxy,也通过.boto添加它(尽管我猜测只有gsutil使用它)。但没有任何作品。谷歌云存储客户端库 - 后面的代理 - 访问桶对象使用Python代码?
我在文档中也找不到任何代理设置。
from google.cloud import storage
storage_client = storage.Client()
bucket = storage_client.get_bucket('my-bucket')
blobs=bucket.list_blobs()
OSERROR:[错误101]网络不可达
* UPDATE 24 JULY-17 - 分辨*
re-installed google cloud storage library and my script works fine with HTTP_PROXY set in the env. Not sure about the root cause for initial troubles and I was not able to reproduce the error again unfortunately.
或者,您可以使用https://github.com/google/apitools并传递用代理初始化的httplib2实例。这是gsutil在使用GCS JSON API时如何与代理协同工作的。代码在这里:https://github.com/GoogleCloudPlatform/gsutil/blob/adf221296d77968b8c7c4bde6dccd235664703ac/gslib/util.py#L786 –
@Mike - 这是不正确的。 python库尊重环境中配置的任何代理设置。请看下面的答案。 – Tuxdude
@Tuxdude - 感谢您的纠正。当我发布这个答案时,我曾看过google-cloud-python源代码,但我没有意识到lib间接支持代理。你能指出我在哪里/如何完成?谢谢。 –