Fix
pandas read_html 403 Forbidden on sports tables: fix
Short answer: read_html downloads the page with a plain Python client before it parses anything, and many servers refuse that client with a 403 by policy. Parsing is not the problem. Skip the page and load the same table from a licensed API with pandas.json_normalize, which returns typed columns instead of markup.
The symptoms
You find a table of team or player stats on a web page, and you reach for the shortcut that pandas offers. One line should turn the page into a list of DataFrames:
import pandas as pd
tables = pd.read_html("https://example.test/standings")Instead of tables you get a traceback that ends in one of these:
HTTPError: HTTP Error 403: Forbidden, raised from the standard library's URL opener.HTTP Error 429: Too Many Requestson a second or third page.ValueError: No tables found, because the server returned a short refusal page or a challenge page with a 200 status and no table.- A different table than the one you saw in your browser, because the browser ran scripts that built it and the plain fetch did not.
The same URL opens fine when you paste it into a browser. That is the part that feels wrong, and it has a simple explanation.
Why it happens
read_html is two steps in one call. First it fetches the page. Then it hands the markup to an HTML parser, which finds each table and builds a DataFrame. By default the fetch uses the Python standard library's URL opener, and that client announces itself in the User-Agent header as Python's URL library. It sends none of the other headers a browser sends, it keeps no cookies, and it does not run any script.
A server is free to decide what it serves to whom. Some sites refuse every request that identifies itself as a script. Some serve it only if it comes from a known address. Some let it through a few times and then answer 429. And some do serve it, but only a shell page, because the table is filled in by a script after the page loads. The 403 is a deliberate answer from the operator, not a fault in pandas.
To show the mechanics without naming anyone, here is a stand-in server that behaves that way. It answers 403 to any client whose User-Agent starts with the standard library's default and 200 to everything else.
import io, threading, http.server, pandas as pd
TABLE = b"<table><tr><th>team</th><th>wins</th></tr><tr><td>A</td><td>10</td></tr></table>"
class H(http.server.BaseHTTPRequestHandler):
def do_GET(self):
ua = self.headers.get("User-Agent", "")
code = 403 if ua.startswith("Python-urllib") else 200
self.send_response(code); self.send_header("Content-Type", "text/html"); self.end_headers()
self.wfile.write(TABLE if code == 200 else b"forbidden")
def log_message(self, *a): pass
srv = http.server.HTTPServer(("127.0.0.1", 8765), H)
threading.Thread(target=srv.serve_forever, daemon=True).start()
try:
pd.read_html("http://127.0.0.1:8765/")
except Exception as e:
print("read_html:", type(e).__name__, e)
print(pd.read_html(io.StringIO(TABLE.decode()))[0].to_dict("records")) # parsing itself is fineThis printed read_html: HTTPError HTTP Error 403: Forbidden and then [{'team': 'A', 'wins': 10}]. The parser handled the table without trouble. Only the fetch was refused. That is the diagnosis to carry to any real site: if the same markup parses when you hand it over as a string, the table is fine and the access is the issue.
What to try, and what not to
Start with the site's terms and its robots file. They say whether automated access is welcome. If they forbid it, the matter ends there. Nothing below is a way around a "no".
If automated access is allowed, a few ordinary steps are worth doing:
- Fetch once, parse many times. Download the page yourself, save the markup, and parse the saved copy. That keeps load on the site low and lets you debug without re-fetching.
- Identify your program honestly. Newer pandas versions let you pass request headers through
storage_options. A clear User-Agent that names your project and a contact address is courteous and is what many operators ask for. - Cache and back off. Do not fetch the same page twice in a day, and wait longer after every 429.
- Watch for script-built tables. If the table is not in the downloaded markup, the page builds it with a script. No parser will find it, and rendering it with a browser is the next question, which has its own page in this series.
What we do not suggest is dressing the client up as a person's browser or changing headers until the refusal stops. If a site has decided scripts are not welcome, that is its decision. The reliable answer is to use a source that wants to be called by programs.
The fix: load the table from an API
The SportsDataHQ API returns rows as JSON with named fields and real types. There is no markup, no table-matching and no guess about which of five tables on a page you want. Pass the rows to json_normalize and you have a DataFrame.
import os, requests, pandas as pd
r = requests.post("https://mcp.endzoneapi.com/v1/get_standings",
headers={"x-api-key": os.environ["SDHQ_KEY"]},
json={"season": 2026}, timeout=30)
r.raise_for_status()
df = pd.json_normalize(r.json()["data"]["standings"])
cols = ["team", "division", "wins", "losses", "ties", "points_for", "points_against"]
print(r.status_code, df.shape)
print(df[cols].sort_values("wins", ascending=False).head(3).to_string(index=False))On the verified run this returned HTTP 200 and a shape of (32, 22). The top three rows were BUF with 10 wins, 1 loss and 326 points for, SF with 10 wins, 1 loss and 336 points for, and KC with 9 wins and 3 losses. The call cost 2 credits. The 22 columns include home and away records, division and conference records and streaks, which no one needs to scrape out of a page.
Why this is more than a workaround
A parsed table has three weaknesses that an API does not. The first is that markup changes without notice. A site moves a column, renames a header or adds a footnote row, and your script either breaks or, worse, loads the wrong numbers without an error. The second is types: every cell arrives as text, so you spend code on converting records like 10-1 and percent strings. The third is scope. A web page shows one season and one view, while a call can take a season, a date range or a team and return exactly that.
An API also tells you things a page cannot. Each response carries a note where a field needs one, and each call reports its credit cost in a response header, so you can see usage as you go. Seasons are named in the sport's own convention, so check the season note for each tool before you join across sports.
When not to use this
- The table is not in the API. Commentary, news and photos are pages, not data. Check the tool list.
- You need history the API does not hold. Coverage starts at different years by sport. Read the coverage section for the sport before you plan a backfill.
- You need a whole season of box scores. That is thousands of rows, and a data package is one download.
- You want a pick. Prices come back as information about the market. No tool recommends a wager.
Try it
- Get a free key: 1,000 credits a month, no card.
- Skip the API and download a data package if you want a full season in a file.
FAQ
Why does pandas read_html return HTTP Error 403 for a page that loads in my browser?
read_html fetches the URL itself with a plain Python client, then parses the tables. The server sees a scripted request that identifies itself as Python and may refuse it by policy. Your browser sends different headers and carries cookies, so the same URL loads for you.
Is changing the User-Agent a good fix?
Not as a way to pass as a browser. If a site refuses scripts, pretending to be a person breaks its rules and tends to fail again. Identifying your program honestly is fine where the terms allow automated access. If they do not, get the data from a licensed source.
How do I get a sports table into a DataFrame without scraping?
Call an API that returns JSON and pass the rows to pandas.json_normalize. A football standings call for season 2026 returned 32 rows and 22 columns on the verification run and cost 2 credits.
Checked against the live API on 2026-12-06. Questions: hello@sportsdatahq.com.