I have the following code built using the Requests module:
import json
import requests
import jsonobject
import simplejson
url = 'http://www.whoscored.com/StatisticsFeed/1/GetPlayerStatistics'
params = {
'category': 'shots',
'subcategory': 'zones',
'statsAccumulationType': '0',
'isCurrent': 'true',
'playerId': '',
'teamIds': '',
'matchId': '',
'stageId': '9155',
'tournamentOptions': '2',
'sortBy': 'Rating',
'sortAscending': '',
'age': '',
'ageComparisonType': '',
'appearances': '',
'appearancesComparisonType': '0',
'field': 'Overall',
'nationality': '',
'positionOptions': '%27FW%27,%27AML%27,%27AMC%27,%27AMR%27,%27ML%27,%27MC%27,%27MR%27,%27DMC%27,%27DL%27,%27DC%27,%27DR%27,%27GK%27,%27Sub%27',
'timeOfTheGameEnd': '5',
'timeOfTheGameStart': '0',
'isMinApp': '',
'page': '1',
'includeZeroValues': '',
'numberOfPlayersToPick': '10'
}
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
'Host': 'www.whoscored.com',
'Referer': 'http://www.whoscored.com/'}
responser = requests.get(url, params=params, headers=headers)
print responser.status_code
responser = json.loads(responser.text.replace("'", '"').decode('cp1252'))
print responser
This is causing the following error:
Traceback (most recent call last):
File "C:\Python27\counter.py", line 41, in <module>
responser = json.loads(responser.text.replace("'", '"').decode('cp1252'))
File "C:\Python27\lib\encodings\cp1252.py", line 15, in decode
return codecs.charmap_decode(input,errors,decoding_table)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
I can see from the status code 200 that the HTTP request was successful, but I am still getting the above error. I have replaced single quotes with double ones as this is an issue I have experienced with this site before. I have also used to the decoding method compatible with Windows Command Shell, but am still having trouble.
Can anyone see what the issue is?
Thanks
json.loads(responser.text.decode(encoding='cp1252'))responser.json()?