Page MenuHomePhabricator

MW API requests to mediawiki.org (without the www subdomain) fail
Closed, ResolvedPublic

Description

Our calls to the MediaWiki API via api-util.js/mwApiGet are returning the auto-generated error HTML page when a domain of 'mediawiki.org' is used. If 'www.mediawiki.org' is used, the request is successful.

Details

Related Gerrit Patches:

Event Timeline

Mholloway created this task.Feb 7 2018, 7:55 PM
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 408863 had a related patch set uploaded (by Mholloway; owner: Mholloway):
[mediawiki/services/mobileapps@master] Throw an error if the MediaWiki API responds with text/html

https://gerrit.wikimedia.org/r/408863

Change 408863 merged by jenkins-bot:
[mediawiki/services/mobileapps@master] Throw an error if the MediaWiki API responds with text/html

https://gerrit.wikimedia.org/r/408863

Mholloway updated the task description. (Show Details)Feb 7 2018, 8:59 PM
bearND added a subscriber: bearND.Feb 7 2018, 9:00 PM

I've merged this since it's definitely an improvement over

{
"status": 400,
"type": "internal_error",
"detail": "400",
"method": "GET",
"uri": "/mediawiki.org/v1/page/mobile-sections/How_to_contribute"
}

When I run the same MW API request our api calls make with curl I get a 301:

$ curl -X POST -d "action=query&lllimit=max&pilicense=any&piprop=thumbnail%7Coriginal%7Cname&pithumbsize=1024&wbptterms=description&inprop=protection&rvprop=ids%7Ctimestamp%7Cuser%7Ccontentmodel&titles=How_to_contribute&prop=coordinates%7Cpageprops%7Cpageimages%7Cpageterms%7Crevisions%7Cinfo%7Clanglinks&format=json&formatversion=2&continue=" "https://mediawiki.org/w/api.php"

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.mediawiki.org/w/api.php">here</a>.</p>
</body></html>

Our output (with your patch applied) shows the API help page instead. Any idea why that is?

Mholloway added a comment.EditedFeb 7 2018, 9:03 PM

I was just about to note the same thing. cURL returns a 301 when POSTing to https://mediawiki.org/w/api.php, but the Postman app (and, evidently, our internal service requests) return 200 and the help page HTML. I'm not sure why this discrepancy exists.

Mentioned in SAL (#wikimedia-operations) [2018-02-07T21:44:26Z] <bsitzmann@tin> Started deploy [mobileapps/deploy@fe3cd60]: Update mobileapps to 7a3b19c (T186745 T186643)

Mentioned in SAL (#wikimedia-operations) [2018-02-07T21:51:07Z] <bsitzmann@tin> Finished deploy [mobileapps/deploy@fe3cd60]: Update mobileapps to 7a3b19c (T186745 T186643) (duration: 06m 41s)

Some comments between @Mholloway and myself on IRC -services channel earlier with minor edits:

As far as POSTing to mediawiki.org, i guess in this case we could just special-case mediawiki.org and rewrite to www.mediawiki.org? seems like kind of a one-off issue.

Since this is a redirect issue I think RB should handle that, just for consistency sake.

This probably shouldn't happen: https://mediawiki.org/api/rest_v1/. I guess it does moot the issue for us, though, at least as far as prod is concerned; those requests will never reach MCS

bearND closed this task as Resolved.Feb 7 2018, 10:40 PM
bearND claimed this task.

For posterity and completeness, you are witnessing the difference because Varnish does the redirect in this case. This is why you get the help page in a browser (which automatically follow redirects), a 301 with curl and an error with api-util (because that request hits the MW API servers directly, which do not have the notion of domain redirects).