Skip to content

Fix auto_setup Sci-Hub probe crash: 'int' object has no attribute 'get'#13

Open
cj20092008-boop wants to merge 1 commit into
Rimagination:masterfrom
cj20092008-boop:fix/auto-setup-scihub-probe-int-get
Open

Fix auto_setup Sci-Hub probe crash: 'int' object has no attribute 'get'#13
cj20092008-boop wants to merge 1 commit into
Rimagination:masterfrom
cj20092008-boop:fix/auto-setup-scihub-probe-int-get

Conversation

@cj20092008-boop
Copy link
Copy Markdown

Summary

scansci_pdf_auto_setup always reports a Sci-Hub probe failure even though the probe itself completes successfully:

"Sci-Hub probe error: 'int' object has no attribute 'get'"

The domain probe runs fine — the crash is in the result-summarization line that counts reachable domains.

Root cause

load_stats() (in domain_db.py) returns per-domain dicts plus a metadata entry _last_probe, whose value is an int timestamp:

# domain_db.py
stats["_last_probe"] = int(m["value"])

In server.py (scansci_pdf_auto_setup), the summary comprehension evaluates s.get("reachable") before the _-prefix guard:

# server.py (before)
reachable = [d for d, s in stats.items() if s.get("reachable") and not d.startswith("_")]

Because Python evaluates the left operand of and first, for the _last_probe key s is an int, so s.get(...) raises 'int' object has no attribute 'get' before not d.startswith("_") ever runs.

Fix

Reorder the conditions so the _-prefixed metadata keys are filtered out first (short-circuit), and add an isinstance(s, dict) guard for robustness:

reachable = [d for d, s in stats.items()
             if not d.startswith("_") and isinstance(s, dict) and s.get("reachable")]

Verification

With the patch applied, the probe + summary runs cleanly:

OK, reachable domains: 4
['https://sci-hub.st', 'https://sci-hub.ru', 'https://sci-hub.ee', 'https://sci-hub.41610.org']

scansci_pdf_auto_setup now reports e.g. Sci-Hub: 4 domains reachable instead of the error.

Environment

  • scansci-pdf 1.5.0
  • Windows 10, Python (uv-managed venv)

load_stats() returns per-domain dicts plus a `_last_probe` metadata
entry whose value is an int timestamp. The summary comprehension in
scansci_pdf_auto_setup evaluated s.get("reachable") before the
`_`-prefix guard, so for `_last_probe` it called .get() on an int and
raised "'int' object has no attribute 'get'", surfacing as a spurious
"Sci-Hub probe error" even though the probe itself succeeded.

Reorder the conditions to filter `_`-prefixed metadata keys first and
add an isinstance(s, dict) guard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant