PythonAnywhere上的JSONDecodeError

我正在尝试在 PythonAnywhere上部署我的应用程序.一切都运行正常,但是当我调用一个函数时,我的应用程序失败了.

异常类型:JSONDecodeError
异常值:期望值:第1行第1列(char 0)

Error Imgur image part 1

Error Imgur image part 2

我一直在读另一个答案,但没有人为我工作.问题是这段代码:

        parametros = {'location': lugar, 'API_KEY': api_code}
        url = 'http://servizos.meteogalicia.es/apiv3/findPlaces'

        # Enviamos la peticion
        peticion = requests.get(url, parametros)

        # Obtenemos la respuesta
        respuesta = json.loads(peticion.text)

更新1

同样的错误:

        parametros = {'location': lugar, 'API_KEY': api_code, 'format': 'application/json'}
        url = 'http://servizos.meteogalicia.es/apiv3/findPlaces'

        # Enviamos la peticion
        try:
            peticion = requests.get(url, parametros)
        except:
            peticion.raise_for_status()

        # Obtenemos la respuesta
        respuesta = json.loads(peticion.text)

JSON似乎是有效的:

JSON validation

最佳答案 (代表OP发布).

我收到了这条支持消息,所以问题解决了:

Ah! Sorry, I really should have spotted that first. Free users are restricted to accessing sites on a whitelist of websites with official documented APIs, and for some reason I thought the site was already on the whitelist.

I’ll add it now and let you know when it’s active.

点赞