WebFaction
Community site: login faq

I recently created a flask app and uploaded it successfully to a webapp directory created on Webfaction. I stored credentials into environment variables in my apache's bin/start script. After inserting configuration code (down below) into my former basic flask app, which contained nothing more than a route to '/' and a message that said "Hello world", I immediately got a 500 internal server error. What am I doing wrong here? And how do I fix this?

init.py

 app.config.update(dict(
        DEBUG = True,
        MAIL_SERVER = 'SERVER_GOES_HERE'',
        MAIL_PORT = PORT_GOES_HERE,
        MAIL_USE_TLS = BOOL_GOES_HERE,
        MAIL_USE_SSL = BOOL_GOES_HERE,
        MAIL_USERNAME = os.environ['USER'],
        MAIL_PASSWORD = os.environ['PASS'],
    ))

start

#!/bin/bash

export USER=USERNAMEGOESHERE
export PASS=PASSGOESHERE

LD_LIBRARY_PATH= DEFAULT_CONTENT_GOES_HERE

error logs (simplified to show details)

File "/home/username/webapps/myapp/wsgi.py", line 3, in <module>
   from myapp import app as application

   File "/home/username/webapps/myapp/myapp/__init__.py", line 32, in <module>
   MAIL_USERNAME = os.environ['USER'],

   File "/usr/lib64/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
    KeyError: 'USER'

asked 01 Dec '15, 20:39

Guled
1538
accept rate: 100%

edited 01 Dec '15, 21:10


Just found my mistake! All I had to do was add the environment variables to my .bash_profile.

  1. $HOME/.bash_profile
  2. Added Environment variables
  3. Entered source $HOME/.bash_profile and pressed 'ENTER'

Also, I was using os.environ incorrectly. I needed to use the get function like so:

os.environ.get('NAME_GOES_HERE')

EDIT:

I recommend to store your environment variables in your apache/bin/start script. I made a mistake placing it in the bash_profile. Correct me if I am wrong by making a comment below.

permanent link

answered 01 Dec '15, 21:45

Guled
1538
accept rate: 100%

edited 03 Dec '15, 23:26

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×113
×55
×52
×44

question asked: 01 Dec '15, 20:39

question was seen: 3,686 times

last updated: 03 Dec '15, 23:26

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM