Hugo L.M
Hugo L.M

Reputation: 1083

JSONDecodeError on PythonAnywhere

I'm trying to deploy my app on PythonAnywhere. Everything is running ok, but when I call a function, my app fails.

Exception Type: JSONDecodeError Exception Value: Expecting value: line 1 column 1 (char 0)

Error Imgur image part 1

Error Imgur image part 2

I have been reading another answers, but no one is working for me. The problem is this piece of code:

        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)

UPDATE 1

The same error:

        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)

And the JSON seems to be valid:

JSON validation

Upvotes: 4

Views: 356

Answers (2)

halfer
halfer

Reputation: 20437

(Posted on behalf of the OP).

I received this support message, so the problem is solved:

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.

Upvotes: 2

Bruce
Bruce

Reputation: 1380

The problem is probably here:

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

It seems that peticion.text is not a valid JSON string.

Upvotes: 0

Related Questions