|
|
@@ -77,11 +77,18 @@ def http(method, url, data=None, headers=None, timeout=30):
|
|
|
request.add_header("Content-Type", "application/x-www-form-urlencoded")
|
|
|
for key, value in (headers or {}).items():
|
|
|
request.add_header(key, value)
|
|
|
- try:
|
|
|
- with urllib.request.urlopen(request, timeout=timeout) as response:
|
|
|
- return response.status, response.read().decode()
|
|
|
- except urllib.error.HTTPError as error:
|
|
|
- return error.code, error.read().decode()
|
|
|
+ # One retry on a dropped connection: the freshly started app can
|
|
|
+ # close a very early keep-alive connection once while warming up.
|
|
|
+ for attempt in range(2):
|
|
|
+ try:
|
|
|
+ with urllib.request.urlopen(request, timeout=timeout) as response:
|
|
|
+ return response.status, response.read().decode()
|
|
|
+ except urllib.error.HTTPError as error:
|
|
|
+ return error.code, error.read().decode()
|
|
|
+ except (urllib.error.URLError, OSError):
|
|
|
+ if attempt > 0:
|
|
|
+ raise
|
|
|
+ time.sleep(0.5)
|
|
|
|
|
|
|
|
|
def directives(uri, auth=None):
|