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.

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

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.

Python Flask for Beginners: Build a CRUD Web App with Python and Flask

In this Python Flask tutorial, you'll learn to build CRUD web applications using Python and Flask. Python and Flask can make building a CRUD app super easy.

Python Tutorial: Working with JSON Data using the json Module

In this Python Programming Tutorial, we will be learning how to work with JSON data. We will learn how to load JSON into Python objects from strings and how to convert Python objects into JSON strings. We will also see how to load JSON from a file and save those Python objects back to files