当 Google Compute Engine 实例(使用 Container-Optimized OS 镜像)启动并且 dockerized 应用程序运行时,下面的脚本应该将数据发送到 url。 不幸的是,即使它无法发布数据,应用程序运行时也会收到数据。
输出是:
('Error', ConnectionError(MaxRetryError("HTTPConnectionPool(host='34.7.8.8', port=12345): Max retries exceeded with url: /didi.json (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))",),))
它来自 GCE 吗?
这是python代码:
for i in range(0,100):
while True:
try:
response = requests.post('http://%s:12345/didi.json' % ip_of_instance, data=data)
except requests.exceptions.RequestException as err:
print ("Error",err)
time.sleep(2)
continue
break
编辑 - 这是发布请求的参数:
data = {
'url': 'www.website.com',
'project': 'webCrawl',
'spider': 'indexer',
'setting': 'ELASTICSEARCH_SERVERS=92.xx.xx.xx',
'protocol': 'https',
'scraper': 'light'
}
请您参考如下方法:
我看到的是你正在使用一个 while true 循环,当它超过最大重试次数时你会收到一个错误,因为你被服务器禁止了,但这种状态不会永远持续下去,当禁止被移除时你开始获取更多数据,因为它仍在运行。
如果我的理论不正确,你可以看看这个其他线程。
