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 using http instead of https.

  1. Why is this happening?
  2. 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):
    return True
    return False
# configure application
app = Flask(__name__)

# ensure responses aren't cached
if app.config["DEBUG"]:
    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"
# configure CS50 Library to use SQLite database
db = SQL("sqlite:///mashup.db")
cities = 0
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"))
  • Any luck figuring out why you had this issue? I am having the same problem with pset7. – Rad Dec 14 '17 at 18:53
  • Yes, it was because you had to use the scheme parameter of redirect and set it to https. Look at flask documentation if you need help – ssk4988 Dec 17 '17 at 19:12
  • I added the config parameter app.config["PREFERRED_URL_SCHEME"] = 'https' but I am still getting the same error when redirecting to index.html. – Rad Dec 17 '17 at 20:09
  • I think it was something like url_for('secure_thingy', _external=True, _scheme='https') – ssk4988 Dec 19 '17 at 11:35

David Malan posted in https://github.com/cs50/python-cs50/pull/65 and that solves the problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .