JSON Parsing stops working when used with Flask on PythonAnywhere

JSON Parsing stops working when used with Flask on PythonAnywhere

I'm using Flask and PythonAnywhere to deploy a small new server which takes latitude/longitude arrays, sends this to the Bing Maps Snap-to-Road API which says that it would return a JSON file. However, the json.loads() always stops working ONLY when used on PythonAnywhere.

I'm using Flask and PythonAnywhere to deploy a small new server which takes latitude/longitude arrays, sends this to the Bing Maps Snap-to-Road API which says that it would return a JSON file. However, the json.loads() always stops working ONLY when used on PythonAnywhere.

As of right now, I've tried the code on two local machines and it works fine. The PythonAnywhere instance is using Python 3.7, and I've tried the Bing Maps JSON code on both a Python 3.6 local machine and a Python 3.7 machine. I've even uploaded the file that I used for testing (not the entire server code, as that is fairly long), but the Bing Maps API code, onto PythonAnywhere and tested on their Python interpreter(both 3.7 and 3.6) and it seems to have worked fine, returning the two expected arrays.

import requests
lngArray = [array of longitudes stored as floats]
latArray = [array of latitudes stored as floats]
snappedLatArray = []
snappedLngArray = []

arrayLength = len(lngArray) apiKey ="my-API-Key" baseURL = "http://dev.virtualearth.net/REST/v1/Routes/SnapToRoad?points=" for i in range(0,arrayLength): baseURL = baseURL+(str(latArray[i])[:9])+","+(str(lngArray[i])[:9]) if (i != (arrayLength - 1)): baseURL = baseURL + ";" elif(i == (arrayLength - 1)): pass

finalURL = baseURL+"&interpolate=true&key="+apiKey print(finalURL)

c = requests.get(finalURL) snappedPointsDict = c.json() snappedPoints = snappedPointsDict['resourceSets'][0]['resources'][0] ['snappedPoints'] for x in snappedPoints: snappedLat = x['coordinate']['latitude'] snappedLng = x['coordinate']['longitude'] snappedLatArray.append(snappedLat) snappedLngArray.append(snappedLng)

On my machine and when run as a standalone program (such as the one above), it works flawlessly, and the snappedLatArray and snappedLngArray output arrays of latitudes and longitudes respectively. However, when run in a Flask environment, it fails, and in the error log it shows simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0) and the app stops working.

python json flask

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

JSON with Python - copyassignment.com

Before we get started with how to use JSON with Python, we’ll take a look at “What is JSON?”.The JSON stands for JavaScript Object Notation.

【Python / SwaggerUI / Flask / JSON】

Currently, I am implementing the API using Swagger UI and Flask, but when I return it in JSON format, "\" is mixed in the response. Below is the current code. @ api.route ('/ test / <id>') cla

How to create a basic JSON API using Python and Flask?

In this Python Flask tutorial, you can learn how to create a basic JSON API using Python and Flask. The JSON API specification is a powerful way for enabling communication between client and server.

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

How To Compare Tesla and Ford Company By Using Magic Methods in Python

Magic Methods are the special methods which gives us the ability to access built in syntactical features such as ‘<’, ‘>’, ‘==’, ‘+’ etc.. You must have worked with such methods without knowing them to be as magic methods. Magic methods can be identified with their names which start with __ and ends with __ like __init__, __call__, __str__ etc. These methods are also called Dunder Methods, because of their name starting and ending with Double Underscore (Dunder).