More unique IPs than any network on the planet, in the world's largest residential pool. That's Shifter.More unique IPs than any network, in the world's largest pool. That's Shifter.

See the numbers

We Tested Four Python robots.txt Parsers Against RFC 9309. Only One Got Everything Right

We ran 20 RFC 9309 test cases through four Python robots.txt parsers. The standard library passed 12 and ignored wildcards. Protego passed all 20.

Engineering · Updated November 29, 2026 · 8 min read
correct of 20 test casesProtego20robotspy18robotexclusion…14urllib.robotparser12
Of four Python parsers, only amber Protego read every RFC 9309 test case correctly.
Knowledge
On this page
  1. The rules that trip parsers up
  2. The test
  3. The results
  4. What goes wrong
  5. Fetching robots.txt matters too
  6. What to use
  7. How we tested
  8. The bottom line
  9. Sources and references

Respecting robots.txt is the baseline of responsible web scraping and crawling, and since September 2022 it has had a formal IETF standard, RFC 9309. But a crawler only respects robots.txt as well as its parser reads it. Read a file wrongly in one direction and you crawl pages a site asked you not to; read it wrongly in the other and you miss pages you were allowed to fetch. We ran 20 test cases built from the RFC through four Python parsers. One got all 20 right. The one built into Python got 12.

The rules that trip parsers up

Most robots.txt files are simple, but RFC 9309 sets precise rules for the cases that are not:

  • Longest match wins. “The most specific match found MUST be used. The most specific match is the match that has the most octets.” The order of the lines does not matter.
  • Ties go to Allow. “If an ‘allow’ rule and a ‘disallow’ rule are equivalent, then the ‘allow’ rule SHOULD be used.”
  • Wildcards are required. Crawlers “MUST support” *, meaning any characters, and $, meaning the end of the path.
  • User-agent matching ignores case, and if several groups name the same bot, their rules “MUST be combined into one group”.
  • Percent-encoded letters are decoded before comparison, so /%62%61%7A matches a rule for /baz.
  • robots.txt itself is always allowed, and rules that appear before any user-agent line should be ignored.

The test

We tested four parsers in Python 3.11:

ParserVersionNotes
urllib.robotparserPython 3.11 standard libraryBuilt in
robotexclusionrulesparser1.7.1An older third-party parser
robotspy0.13.0Calls itself a Robots Exclusion Standard parser
Protego0.7.0Scrapy’s default robots.txt parser

Each case pairs a small robots.txt file with a URL and the answer RFC 9309 requires, for a crawler called ExampleBot. Every case comes from a rule or example in the RFC itself.

The results

ParserCorrect, of 20Too permissiveToo strict
Protego2000
robotspy1811
robotexclusionrulesparser1424
urllib.robotparser1244

“Too permissive” means the parser allowed a URL the file blocks, which is the error that matters most: your crawler fetches pages the site asked it to leave alone. “Too strict” means it blocked a URL the file allows.

Case by case, with ✓ for the RFC answer and ✗ for a wrong one:

CaseRFCurllibrerprobotspyProtego
Longer Allow beats shorter DisallowAllow✗✗✓✓
Same rules, Allow listed firstAllow✓✓✓✓
Longer Disallow beats shorter AllowBlock✗✗✓✓
Equal Allow and DisallowAllow✗✗✓✓
Disallow: /*.pdfBlock✗✓✓✓
Disallow: /*.pdf$, URL with a queryAllow✓✓✓✓
Disallow: /*.pdf$, exactBlock✗✓✓✓
User-agent in another caseBlock✓✓✓✓
User-agent with a versionBlock✓✓✗✓
Two groups for the same botBlock✗✗✓✓
Bot’s own group replaces *Allow✓✓✓✓
Another bot’s groupAllow✓✓✓✓
Several user-agent linesBlock✓✓✓✓
Empty DisallowAllow✓✓✓✓
Allow: /$ for the homepageAllow✗✗✓✓
Percent-encoded pathBlock✓✓✓✓
Rule before any user-agentAllow✓✓✓✓
Rule matching a query stringBlock✓✓✓✓
Path in a different caseAllow✓✓✓✓
/robots.txt itselfAllow✗✗✗✓

What goes wrong

File order instead of longest match. urllib.robotparser and robotexclusionrulesparser apply the first rule that matches. With Disallow: /shop above Allow: /shop/sale, they block the sale pages the site opened up; with Allow: /shop above Disallow: /shop/checkout, they let the crawler into checkout pages the site closed. Our earlier guide to robots.txt and AI opt-out signals flagged the first case; the test shows it cuts both ways.

No wildcards in the standard library. urllib.robotparser treats * and $ as ordinary characters, so Disallow: /*.pdf blocks nothing. This is the most consequential gap: every wildcard rule in a file is silently ignored, and the crawler goes where it was asked not to. For our study of who blocks AI crawlers we had to write our own evaluator for this reason, after the built-in parser misread files such as Disallow: / followed by Allow: /$.

Groups not merged. When a file names the same bot in two places, both older parsers read only one of the groups, so rules in the other are lost.

Version numbers in the user-agent. robotspy did not match ExampleBot/1.0 against a group for ExampleBot. The RFC expects crawlers to match their product token, so pass the bare name, not a full User-Agent string, whatever parser you use.

robots.txt itself. Three parsers reported /robots.txt as blocked when a file disallows everything. That rarely matters in practice, since you fetch robots.txt before asking the parser anything, but it is a sign of how literally each one follows the standard.

Fetching robots.txt matters too

Parsing is half the job. RFC 9309 also says what to do when the file cannot be fetched: a 400 to 499 status means robots.txt is unavailable and the crawler “MAY access any resources on the server”; a server or network error means the crawler “MUST assume complete disallow”. It adds that crawlers “SHOULD NOT use the cached version for more than 24 hours”.

We checked how urllib.robotparser.read() handles status codes. It treated 404 as allow-all and 500 and 503 as disallow-all, as the RFC requires. It treated 401 and 403 as disallow-all, which is stricter than the RFC requires but errs on the safe side.

What to use

If you crawl with Scrapy, you already use Protego: it is Scrapy’s default ROBOTSTXT_PARSER. Elsewhere, it works on its own:

from protego import Protego

rules = Protego.parse(robots_txt)
if rules.can_fetch("https://example.com/shop/sale/shoes", "ExampleBot"):
    ...  # allowed

If you are tied to urllib.robotparser, treat any file that uses *, $, overlapping Allow and Disallow rules or repeated user-agent groups as something it cannot read correctly, and handle those files another way.

Whatever you use, the rest of a responsible setup still applies: identify your crawler, keep request rates reasonable, cache robots.txt for no more than a day, and record what you collected and why, as our template for a company data collection policy describes. Proxies change where your requests come from, not what the site asked of you; teams using residential proxies for data collection should apply the same robots.txt rules whichever exit a request leaves from. Our guide to rotating residential proxies in Scrapy shows how the two fit together.

How we tested

On 29 November 2026 we wrote 20 test cases from the matching rules and examples in RFC 9309, sections 2.2.1 to 2.2.3, each a robots.txt file, a URL and the RFC’s expected answer for a crawler named ExampleBot. We ran every case through each parser’s own permission check in Python 3.11.10. For fetch behaviour, we served robots.txt from a local test server with status codes 200, 401, 403, 404, 500 and 503 and read it with urllib.robotparser.read(). Where the RFC says SHOULD rather than MUST, as for ties and case-sensitive paths, we counted the RFC’s preferred behaviour as correct.

The bottom line

Robots.txt is only as respected as it is parsed. Python’s built-in parser got 12 of our 20 RFC 9309 cases right, ignoring wildcards and reading rules in file order, which means it can crawl pages a site has blocked. Protego, Scrapy’s default, got all 20. Use a parser that follows the standard, pass your bot’s bare name, and treat a server error on robots.txt as a no.

Sources and references

Frequently asked questions

Is Python's urllib.robotparser compliant with RFC 9309?

Not fully. In our test of 20 cases taken from RFC 9309, the standard library's urllib.robotparser in Python 3.11 gave the right answer in 12. It does not support the * and $ wildcards, applies rules in file order instead of by longest match, and does not merge two groups for the same bot.

Which Python robots.txt parser follows RFC 9309?

Protego, the parser Scrapy uses by default, passed all 20 of our test cases. robotspy passed 18, robotexclusionrulesparser 14 and urllib.robotparser 12.

How does RFC 9309 decide between Allow and Disallow?

By the most specific match, meaning the rule that matches the most characters of the path, regardless of the order of the lines. If an Allow and a Disallow rule are equally specific, the Allow rule should be used.

What should a crawler do if robots.txt returns an error?

RFC 9309 says that if robots.txt is unavailable, with an HTTP status in the 400 to 499 range, the crawler may access any resource. If it is unreachable because of a server or network error, such as a 500 to 599 status, the crawler must assume complete disallow.

Ready to get started?

Try Shifter's residential proxies, 205M+ IPs, 195+ countries, from $0.10/GB.

Get Started