Procházet zdrojové kódy

Catch socket.timeout, which is a separate exception class from TimeoutError before Python 3.10

master
JustAnotherArchivist před 2 roky
rodič
revize
0b34268210
1 změnil soubory, kde provedl 3 přidání a 1 odebrání
  1. +3
    -1
      ia-cdx-search

+ 3
- 1
ia-cdx-search Zobrazit soubor

@@ -5,6 +5,7 @@ import http.client
import json
import re
import shlex
import socket
import sys
import time

@@ -35,7 +36,8 @@ def fetch(url, tries, connection):
print(f'Read {len(data)} bytes from {url}', file = sys.stderr)
o = json.loads(data)
break
except (RuntimeError, TimeoutError, http.client.HTTPException, json.JSONDecodeError) as e:
except (RuntimeError, TimeoutError, socket.timeout, http.client.HTTPException, json.JSONDecodeError) as e:
# socket.timeout is an alias of TimeoutError from Python 3.10 but still needs to be caught explicitly for older versions
print(f'Error retrieving {url}: {type(e).__module__}.{type(e).__name__} {e!s}', file = sys.stderr)
connection.close()
connection = make_connection()


Načítá se…
Zrušit
Uložit