PythonAnywhere 上的 JSONDecodeError

JSONDecodeError on PythonAnywhere

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

异常类型:JSONDecodeError 异常值:预期值:第 1 行第 1 列(字符 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

问题大概出在这里:

File "./consulta/views.py" in formulario
  32.             respuesta = json.loads(peticion.text)

peticion.text 似乎不是有效的 JSON 字符串。

(代表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.