Page MenuHomePhabricator
Paste P8914

Strange API behavior
ActivePublic

Authored by Earwig on Aug 15 2019, 4:58 AM.
Tags
None
Referenced Files
F30036000: raw.txt
Aug 15 2019, 4:58 AM
Subscribers
None
(venv)tools.copyvios@tools-sgebastion-07:~$ python
Python 2.7.9 (default, Sep 25 2018, 20:42:16)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> from urllib import urlencode
>>> session = requests.Session()
>>> session.headers["User-Agent"] = "EarwigBot/0.4.dev0 (wikipedia.earwig@gmail.com)"
>>> url = "https://en.wikipedia.org/w/api.php"
>>> params = {"action": "query", "format": "json", "prop": "info|revisions", "inprop": "protection|url", "rvprop": "content|timestamp", "rvlimit": "1", "rvslots": "main", "titles": "User:The_Earwig"}
>>> data = urlencode(params)
>>>
>>> resp = session.post(url, data=data)
>>> resp.json()
{u'query': {u'normalized': ...<snip>
>>>
>>>
>>> resp = session.post(url, data=data)
>>> resp.json()
{u'query': {u'normalized': ...<snip>
>>>
>>>
>>> resp = session.post(url, data=data)
>>> resp.json()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/data/project/copyvios/venv/local/lib/python2.7/site-packages/requests-2.21.0-py2.7.egg/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
>>> resp.text[:1024]
u'<!DOCTYPE html>\n<html class="client-nojs" lang="en" dir="ltr">\n<head>\n<meta charset="UTF-8"/>\n<title>MediaWiki API help - Wikipedia</title>\n<script>document.documentElement.className=document.documentElement.className.replace(/(^|\\s)client-nojs(\\s|$)/,"$1client-js$2");RLCONF={"wgCanonicalNamespace":"Special","wgCanonicalSpecialPageName":"ApiHelp","wgNamespaceNumber":-1,"wgPageName":"Special:ApiHelp","wgTitle":"ApiHelp","wgCurRevisionId":0,"wgRevisionId":0,"wgArticleId":0,"wgIsArticle":!1,"wgIsRedirect":!1,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":[],"wgBreakFrames":!0,"wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgMonthNamesShort":["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"wgRelevantPageName":"Special:ApiHe'
>>> resp.headers
{'X-Cache-Status': 'pass', 'Content-language': 'en', 'X-Powered-By': 'PHP/7.2.16-1+0~20190307202415.17+stretch~1.gbpa7be82+wmf1', 'Transfer-Encoding': 'chunked', 'X-Frame-Options': 'SAMEORIGIN', 'X-Client-IP': '172.16.7.167', 'Content-Disposition': 'inline; filename=api-help.html', 'Expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'Date': 'Thu, 15 Aug 2019 04:47:02 GMT', 'Age': '0', 'X-Varnish': '587871024, 305756954', 'X-Cache': 'cp1085 pass, cp1075 pass', 'Accept-Ranges': 'bytes', 'Strict-Transport-Security': 'max-age=106384710; includeSubDomains; preload', 'Server': 'mw1224.eqiad.wmnet', 'Connection': 'keep-alive', 'P3P': 'CP="This is not a P3P policy! See https://en.wikipedia.org/wiki/Special:CentralAutoLogin/P3P for more info."', 'X-Analytics': 'ns=-1;special=ApiHelp;WMF-Last-Access=15-Aug-2019;WMF-Last-Access-Global=15-Aug-2019;https=1', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Vary': 'Accept-Encoding,Cookie,Authorization,X-Seven', 'Server-Timing': 'cache;desc="pass"', 'Cache-Control': 'private, must-revalidate, max-age=0', 'Content-Type': 'text/html; charset=utf-8', 'Backend-Timing': 'D=300906 t=1565844421795293'}