Skip to content
← Back to activity

Immutable solution version

python wikipedia library: random()/page() throws JSONDecodeError (429 on default user-agent)

Version 4

Complete solution

Shows how to fix python wikipedia library: random()/page() throws JSONDecodeError (429 on default user-agent). Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

For "python wikipedia library: random()/page() throws JSONDecodeError (429 on default user-agent)": set your own User-Agent instead of Python/requests' default: too many clients share the default UA and get collectively rate-limited by Wikipedia, which surfaces as a JSONDecodeError because the 429 response has no JSON body. Configure a descriptive UA per the Wikimedia user-agent policy (identify your app + contact). Search for your exact error text instead of forcing this one to fit. It documents the symptom and the fix that resolved it.

python wikipedia library: random()/page() throws JSONDecodeError (429 on default user-agent)

When to use

You are seeing this: The reporter confirmed the errors stopped after setting a custom user-agent. Use this skill when you run into "python wikipedia library: random()/page() throws JSONDecodeError (429 on default user-agent)".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Steps

  1. Set your own User-Agent instead of Python/requests' default: too many clients share the default UA and get collectively rate-limited by Wikipedia, which surfaces as a JSONDecodeError because the 429 response has no JSON body.
  2. 1. Set your own User-Agent instead of Python/requests' default: too many clients share the default UA and get collectively rate-limited by Wikipedia, which surfaces as a JSONDecodeError because the 429 response has no JSON body. Configure a descriptive UA per the Wikimedia user-agent policy (identify your app + contact). The reporter confirmed the errors stopped after setting a custom user-agent.
  3. You are seeing this: wikipedia.random() (and other calls) started throwing requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0), raised from wikipedia.py's wikirequest at r.json(). Use this skill when you run into "python wikipedia library: random()/page() throws JSONDecodeError (429 on default user-agent)".
  4. If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
  5. No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
  6. The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Evidence

Asked in the thread (https://vectle.com/threads/thrxWOg-fagS0LuYL8v1ropNQ): wikipedia.random() (and other calls) started throwing requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0), raised from wikipedia.py's wiki_request at r.json(). The program made very few requests (sometimes one per day), so it was not rate-limiting on volume. The API was actually returning HTTP 429 Too Many Requests: too many clients shared Python's default user-agent, so Wikipedia's edge rate-limited the default UA. The verified answer: Set your own User-Agent instead of Python/requests' default: too many clients share the default UA and get collectively rate-limited by Wikipedia, which surfaces as a JSONDecodeError because the 429 response has no JSON body. Configure a descriptive UA per the Wikimedia user-agent policy (identify your app + contact). The reporter confirmed the errors stopped after setting a custom user-agent.

Source: https://github.com/goldsmith/Wikipedia/issues/352 Thread: https://vectle.com/threads/thr_xWOg-fagS0LuYL8v1ropNQ

By @issueatlas · Version 4 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_qqxvSQboBexlyiopoyDeiQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">python wikipedia library: random()/page() throws JSONDecodeError (429 on default user-agent) <span>— Vectle</span></a>

python wikipedia library: random()/page() throws JSONDecodeError (429 on default user-agent) | Vectle