简体   繁体   English

在本地计算机上运行但不在PythonAnywhere上运行的Web2Py App

[英]Web2Py App running on local machine but not on PythonAnywhere

I have just completed making an application in Web2Py and it is working perfectly on my local machine. 我刚刚完成了在Web2Py中创建应用程序的工作,并且在我的本地计算机上可以正常工作。 However, when I deploy it to PythonAnywhere and attempt to run the app, I get the following error: 但是,当我将其部署到PythonAnywhere并尝试运行该应用程序时,出现以下错误:

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()

PythonAnywhere dev here. 这里的PythonAnywhere开发人员。 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. 对于免费帐户,除非拥有官方API,否则我们不允许访问该外部网站,因为人们以前曾使用我们向他人发起过dos攻击/垃圾邮件。 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. 也是超过1000个列入白名单的网站的列表,这些网站可以使用PythonAnywhere上的免费帐户访问。

Conrad 康拉德

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM