当循环继续运行时

2024-05-08 11:56:11 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的脚本应该在Google计算引擎实例(使用容器优化的OS映像)启动并且停靠的应用程序工作时将数据发送到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',))",),))

它来自普通中等教育吗?你知道吗

下面是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

编辑-以下是post请求的参数:

data = {
      'url': 'www.website.com',
      'project': 'webCrawl',
      'spider': 'indexer',
      'setting': 'ELASTICSEARCH_SERVERS=92.xx.xx.xx',
      'protocol': 'https',
      'scraper': 'light'
    }

Tags: 数据实例引擎脚本json应用程序urldata
1条回答
网友
1楼 · 发布于 2024-05-08 11:56:11

我看到的是,您使用的是while true循环,当它超过最大重试次数时,您会收到一个错误,因为您被服务器禁止,但此状态不会永远持续很久;当禁止被删除时,您会开始获得更多数据,因为该循环仍在运行。你知道吗

如果我的理论不对,你可以看看另一条线索。你知道吗

Max retries exceeded with URL

相关问题 更多 >