Skip to content

fix: send a named User-Agent when checking documentation URLs - #355

Merged
neuromechanist merged 1 commit into
developfrom
fix/doc-url-check-user-agent
Sep 10, 2026
Merged

neuromechanist merged 1 commit into
developfrom
fix/doc-url-check-user-agent

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

test_documentation_urls_accessible[openneuropet] was reporting a working page
as broken
, and the openneuropet docs were never the problem.

What is actually happening

The PetSurfer entry points at surfer.nmr.mgh.harvard.edu/fswiki/PetSurfer --
FreeSurfer's wiki, a third-party host. Measured three ways:

Client Status
requests.head, default UA (python-requests/2.32.5) 403
requests.head, browser UA 200
curl -I, faking python-requests/2.32.3 200

So something in what requests sends as a whole is being refused, not the UA
string on its own. Either way the page serves fine to a human, so there is nothing
for @CPernet, @martinnorgaard or @mathesong to fix on their side -- flagging them
only because it was their community's test showing red.

The fix

Send a named User-Agent identifying the project. That is also the polite thing
to do when hitting someone else's server on a schedule, rather than arriving as an
anonymous library default.

And fall back to GET when HEAD returns 403 or 405. Some hosts and CDNs refuse
HEAD outright or treat it as suspicious while serving the same URL happily over
GET, and the question this test asks is whether the page exists -- not whether the
host implements HEAD.

Verification

pytest -m network -k documentation_urls_accessible: openneuropet now passes,
along with every other community.

nemar still fails on this branch, for an unrelated reason: the /dataset URL I
introduced in #352, which #354 fixes. The two are independent and both are
needed.

test_documentation_urls_accessible reported a WORKING page as broken. The
openneuropet PetSurfer entry points at surfer.nmr.mgh.harvard.edu, a
third-party FreeSurfer host, which answers 403 to requests' default
python-requests/2.32.5 and 200 to a browser UA. Measured both ways, plus curl
with the same UA string getting 200, so the block is on what requests sends as
a whole rather than the string alone.

Nothing was wrong with openneuropet's docs, and nothing for its maintainers to
fix: the page serves fine to a human. The checker was the problem.

It now sends a named UA identifying the project, which is also the polite thing
to do when hitting someone else's server on a schedule, and falls back to GET
when HEAD comes back 403 or 405. Some hosts and CDNs refuse HEAD while serving
the same URL happily over GET, and the question here is whether the page
exists, not whether the host implements HEAD.

Verified: openneuropet now passes, and so do bids, eeglab, hed, mne,
openneuropet, and the rest. nemar still fails on this branch for an unrelated
reason -- the /dataset URL I introduced in #352 -- which #354 fixes.
@neuromechanist
neuromechanist force-pushed the fix/doc-url-check-user-agent branch from 2a17df2 to 88705bb Compare September 10, 2026 05:55
@neuromechanist
neuromechanist merged commit 5c57170 into develop Sep 10, 2026
4 of 6 checks passed
@neuromechanist
neuromechanist deleted the fix/doc-url-check-user-agent branch September 10, 2026 06:00
@pwighton

pwighton commented Sep 10, 2026 •

Copy link
Copy Markdown

Hi @neuromechanist, I can pass this along to our networking team to have a look.

I just want to confirm that this is the minimal test that reproduces the issue?

python3 -c "import requests; print(requests.head('https://surfer.nmr.mgh.harvard.edu/fswiki/PetSurfer').status_code)"

Returns a 403

@pwighton

Copy link
Copy Markdown

Hi again @neuromechanist,

The response I got from our network admin is:

In trying to reduce the load on the server I have implemented anti-bot rules that for example take into account the number of times in the past N seconds a client has requested a page and it will give 403s when a threshold is reached.

Are you able to pass along the IP address or range the requests came from? We might be able to look into this further and perhaps make some exceptions. You can sent it to me privately at pwighton @ mgh.harvard.edu if you don't want to post it here.

@paulraines68

Copy link
Copy Markdown

I am the network admin. I have adjusted numbers that were definitely too aggressive. Try again now.

@pwighton

Copy link
Copy Markdown

Thanks @paulraines68!

@neuromechanist

Copy link
Copy Markdown
Member Author

Thanks @paulraines68 and @pwighton, the 403s stopped after the rate-limit change.

A separate report, in case it helps: as of 2026-09-29 18:39 PDT, surfer.nmr.mgh.harvard.edu (132.183.1.43) refuses connections on ports 80 and 443, from two unrelated networks (my machine and a hosted fetch service).
It looks like an outage rather than the anti-bot rules.
Nothing is needed from us; I am just letting you know, and we will look again once it is back.

neuromechanist added a commit that referenced this pull request Sep 30, 2026
The file had sections for 0.8.10, 0.8.12, 0.8.14 and 0.8.15 only. The
three missing releases are written from the pull requests between their
tags (0.8.13: #438, #440, #441, #443; 0.8.11: #418; 0.8.9: #351 to #355
and #359 and #367), so the last seven releases are now all present.

Tested: docs only; each entry checked against its pull request's body.
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.

3 participants