bramwell2010 bramwell2010 - 2 years ago 122
JSON Question

python error parsing json

I'm trying to parse the information found in this link here:

What I want to pull is the information under rowSet (so 0, 1, 2, etc will be one entry) enter image description here

Code I'm using:

import requests
urlPlayerLog = ""
responses = requests.get(urlPlayerLog)
dataGameLogs = responses.json()['resultSets'][0]['rowSet']

This was working for me for months and then one day I kept getting the following error:
enter image description here

Which made me think the issue was with dataGameLogs = responses.json()['resultSets'][0]['rowSet'] , but unsure why that is returning an error...

Ken Ken
Answer Source

The webpage might be expecting a web browser to request the data from the URL. Try adding a user-agent to your request.

import requests
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/31.0'}
urlPlayerLog = ""
responses = requests.get(urlPlayerLog, headers=HEADERS)
dataGameLogs = responses.json()['resultSets'][0]['rowSet']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download