Le 05/05/2016 21:56, Trung Dinh a écrit :
I have an issue why trying to parse data fetched from wikipedia api. This is the piece of code that I am using: api_url = 'http://en.wikipedia.org/w/api.phphttp://en.wikipedia.org/w/api.php?action=query&list=recentchanges&rclimit=5000&rctype=edit&rcnamespace=0&rcdir=newer&format=json&rcstart=20160504022715' api_params = 'action=query&list=recentchanges&rclimit=5000&rctype=edit&rcnamespace=0&rcdir=newer&format=json&rcstart=20160504022715http://en.wikipedia.org/w/api.php?action=query&list=recentchanges&rclimit=5000&rctype=edit&rcnamespace=0&rcdir=newer&format=json&rcstart=20160504022715'
f = urllib2.Request(api_url, api_params) print ('requesting ' + api_url + '?' + api_params) source = urllib2.urlopen(f, None, 300).read() source = json.loads(source)
json.loads(source) raised the following exception " Expecting , delimiter: line 1 column 817105 (char 817104"
I tried to use source.encode('utf-8') and some other encodings but they all didn't help. Do we have any workaround for that issue ? Thanks :)
The error is due to the response not being valid json.
Can you have your script write the failing content to a file and share it somewhere? For example via https://phabricator.wikimedia.org/file/upload/
There is a very thin chance that the server/caches actually garbage the tail of some content. I have seen some related discussion about it earlier this week.