Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing IncompleteRead issue #221

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/scribe_data/wikidata/query_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import os
from pathlib import Path
from urllib.error import HTTPError
import time
from http.client import IncompleteRead

from tqdm.auto import tqdm

Expand Down Expand Up @@ -126,10 +128,21 @@ def query_data(languages=None, word_types=None, overwrite=None):

results = None

try:
results = sparql.query().convert()
except HTTPError as err:
print(f"HTTPError with {q}: {err}")
max_retries = 3
retry_delay = 5 # seconds

for attempt in range(max_retries):
try:
results = sparql.query().convert()
break # If successful, break out of the retry loop
except IncompleteRead:
if attempt < max_retries - 1:
print(
f"Incomplete read error occurred. Retrying in {retry_delay} seconds..."
)
time.sleep(retry_delay)
else:
raise

if results is None:
print(f"Nothing returned by the WDQS server for {q}")
Expand Down
Loading