首页 > 解决方案 > 将 GCP 服务与 python 和代理一起使用

问题描述

在工作中,我们有一个代理,经典设置。

我尝试使用我的 python 脚本访问 GCS 存储桶中的文件或在 BigQuery 表上读/写。在另一个网络上一切正常。

我已经在 Ubuntu 上HTTP_PROXY使用代理的 URL 设置了我的环境。HTTPS_PROXY我还apt为浏览器设置了值。我可以apt updategit clone...但是一些简单的事情是df = pd.read_csv("gs://.......")行不通的。

我什至配置gcloud为设置代理的值。

$ gcloud config list      
[compute]
region = europe-west1
zone = europe-west1-c
[core]
account = me@myself.org
disable_usage_reporting = True
project = world-anhilation-666
[proxy]
address = proxy.net
port = 8080
type = http

Your active configuration is: [default]

该脚本运行超过 10 分钟并给了我错误: Cannot connect to host www.googleapis.com:443 ssl:default [Network is unreachable]

标签: pythongoogle-cloud-platformproxy

解决方案


你可以尝试几个选项来解决这个问题

您的 Internet 防火墙阻止了与 google api 的连接:尝试在您的 laravel 主机中 ping android.googleapis.com。或 curl -v gcm-http.googleapis.com 如果它没有响应,很可能它被阻止了。

打开你的端口让google api工作,确保443是开放的,5528-2230。它可能需要在您的防火墙中进行配置

gcm-http.googleapis.com 有很多 ip 地址,所以你需要允许来自这些 ip 地址的连接。这是他们的 IP 地址之一:172.217.24.234 。您可以监控防火墙中的 IP 地址。

您可以在此链接 [1] 和 [2] 上找到 google api IP 地址的范围

[1] https://whois.domaintools.com/172.217.24.234 [2] http://whois.domaintools.com/216.58.196.202


推荐阅读