I am working on my final project using Google Maps to make a game, and I keep running into the same error: ide50-ssk4988.cs50.io didn’t send any data. ERR_EMPTY_RESPONSE
This always seems to happen when I redirect to the index url using Flask's redirect and url_for functions. I have found that this only happens when the GET request is sent singusing http instead of https.
- Why is this happening?
- How do I fix it?
application.py(up until "/"):
import os
import re
from flask import Flask, jsonify, render_template, request, url_for, redirect, flash, session
from flask_session import Session
from flask_jsglue import JSGlue
from tempfile import mkdtemp
from cs50 import SQL
from helpers import *
#credit Daniel Goldberg https://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-number-float
def is_int(value):
try:
int(value)
return True
except:
return False
# configure application
app = Flask(__name__)
JSGlue(app)
# ensure responses aren't cached
if app.config["DEBUG"]:
@app.after_request
def after_request(response):
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Expires"] = 0
response.headers["Pragma"] = "no-cache"
return response
app.config["SESSION_FILE_DIR"] = mkdtemp()
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)
# configure CS50 Library to use SQLite database
db = SQL("sqlite:///mashup.db")
cities = 0
@app.route("/")
@login_required
def index():
"""Render map."""
if not os.environ.get("API_KEY"):
raise RuntimeError("API_KEY not set")
rows=db.execute("SELECT * FROM users WHERE savecode = :savecode", savecode = session["user_id"])
rows2=db.execute("SELECT * FROM transactions WHERE savecode = :savecode", savecode = session["user_id"])
if len(rows)==0:
return redirect(url_for("index"))
return render_template("index.html", key=os.environ.get("API_KEY"), cashvalue= rows[0]["cash"], cities = len(rows2))
redirect line:
return redirect(url_for("index"))