Question

I have a simple application using Flask and MongoEngine and I'm having some trouble maintaining the full functionality on Heroku. I'm not having any errors thrown, but when I actually try to access it, my application throws a 500 error if I try to read from it. This the relevant part of my __init__ file that sets up the connection:

MONGO_URL = os.environ.get("MONGOHQ_URL")

app = Flask(__name__)
if MONGO_URL:
    credentials = re.sub(r"(.*?)//(.*?)(@hatch)", r"\2",MONGO_URL)
    username = credentials.split(":")[0]
    password = credentials.split(":")[1]
    app.config["MONGODB_DB"] = MONGO_URL.split("/")[-1]
    connect(
        MONGO_URL.split("/")[-1],
        host=MONGO_URL,
        port=1043,
        username=username,
        password=password
    )

The log of the error is this:

heroku[router]: at=info method=GET path=/admin/create/ host=tranquil-taiga-1563.herokuapp.com fwd="66.31.20.171" dyno=web.1 connect=2ms service=8ms status=500 bytes=291
app[web.1]: 10.191.63.167 - - "GET /admin/create/ HTTP/1.1" 500 -

Not quite sure if this is relevant, but the file that actually calls the view (in case my assumption about the source of the error is incorrect)

https://gist.github.com/Slater-Victoroff/6148884)

Was it helpful?

Solution

It was kind of a silly problem, but in case somebody comes by here I figure it's worth having a an answer for this problem.

Basically, since I was using WTForms for all of my submissions and whatnot, the above code was very nearly correct. The only change I needed to make (Which WTForms seems to require for csrf authentication) was to add this line:

app.config["SECRET_KEY"] = "secret_key"

Above the connect command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top