Reputation: 33
I have just completed making an application in Web2Py and it is working perfectly on my local machine. However, when I deploy it to PythonAnywhere and attempt to run the app, I get the following error:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I'm not sure why this error is occurring since it works on my local machine. I am getting this error in almost every page of the app. Here is one function where I am getting the error:
def index():
"""Get parameters for current date to pass into url"""
day = time.strftime('%d')
month = time.strftime('%m')
year = time.strftime('%Y')
url = 'http://stats.nba.com/scores/#!/' + month + '/' + day + '/' + year
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36'}
"""Get results from response at NBA.com to obtain standings for Eastern and Western Conference"""
with requests.Session() as session:
session.headers = headers
session.get(url, headers=headers)
params = {
'DayOffset': '0',
'GameDate': month + '/' + day + '/' + year,
'LeagueID': '00'
}
response = session.get('http://stats.nba.com/stats/scoreboardV2?DayOffset=0&LeagueID=00&gameDate='+month+'%2F'+day+'%2F'+year, params=params)
results = response.json()
eastHeaders = results['resultSets'][4]['headers']
eastRows = results['resultSets'][4]['rowSet']
westHeaders = results['resultSets'][5]['headers']
westRows = results['resultSets'][5]['rowSet']
return dict(eastHeaders=eastHeaders,eastRows=eastRows,westHeaders=westHeaders,westRows=westRows)
The specific line where I am getting the error is:
results = response.json()
Upvotes: 1
Views: 144
Reputation: 1913
PythonAnywhere dev here. For free accounts, we do not allow access to an external site unless it has an official API because people have used us to launch dos attacks/spam others before. For more details see here.
Also here is a list of the over 1000+ whitelisted sites with APIs that you can access with a free account on PythonAnywhere.
Conrad
Upvotes: 2