Thursday, December 11, 2014

Setting A WTForm Default Date To Today/Now

http://stackoverflow.com/a/27424739/1364191

It's definitely a common mistake for people using WTForms. When you create a form and use something like datetime.date.today() as a default value, that value will always stay the same. The fix is to use "datetime.date.today" instead of "datetime.date.today()".

Friday, December 5, 2014

Dokku Flask Port and Host


In your flask application, you need to:

  • Set default port=5000 (this seems to be Dokku's default too)
  • Set default host=0.0.0.0 (this allows your host server to connect to the container)

In your Procfile:
web: gunicorn main:app
or (without gunicorn)
web: python <your-app>.py

If you still can't connect to your application after it deploys, see this: http://www.paulsprogrammingnotes.com/2014/12/troubleshooting-dokku-not-accessible.html

Troubleshooting Dokku Not Accessible

First, make sure your application isn't giving any errors when it attempts to run:
dokku run <your-app> "<whatever is in your proc file>"

Get the :port number from the line with "upstream" in the following file: /home/dokku/<your-app>/nginx.conf

Try to "wget 127.0.0.1:<your-port>" from the host. Will it connect?

Thursday, December 4, 2014

"Requested runtime not available for this stack" - Dokku

While using Dokku, I was getting the following error message: Requested runtime (python-2.7.8) is not available for this stack (cedar-14).

This was due to a connection error between my docker container and the internet. To determine this, I ran "docker images" and got the image id of "programium/buildstep", then got into a container with the following command: sudo docker run -t -i <your image id> /bin/bash

Once in the container, I ran:
curl http://lang-python.s3.amazonaws.com/cedar/runtimes/python-2.7.8.tar.gz -s

If that is unsuccessful, that should confirm it's a connection issue.

This was the solution to the problem: http://www.paulsprogrammingnotes.com/2014/12/rebuilding-buildstep-image-for-dokku.html

Tuesday, December 2, 2014

Rebuilding Buildstep Image For Dokku From Behind Proxy

I had to change the buildstep image's docker file to add my proxy. This is because the buildstep image required a proxy before the build to download the python buildpack.

I was rebuilding the buildstep image for dokku with these instructions: https://github.com/progrium/dokku/commit/9ebf453b72cab3a16ea261284236bb7c20ca3a1a#diff-04c6e90faac2675aa89e2176d2eec7d8R101

I'm behind a proxy, so I was getting this error when I ran "sudo make build":
Cloning into 'heroku-buildpack-multi'...
fatal: unable to access 'https://github.com/ddollar/heroku-buildpack-multi.git/': Failed to connect to github.com port 443: Connection timed out

The solution? Replace the Dockerfile in the root of the folder you git cloned with this:

Monday, December 1, 2014

Troubleshooting Pip Timeout - Python

Timeout: (<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x27330d0>, 'Connection to pypi.python.org timed out. (connect timeout=15)')

If you're installing several requirements from a requirements.txt file, it helps to use "-v" after your pip install command to figure out which module has the timeout. Most likely, it's trying to download a module from a URL that doesn't exist.

Friday, November 28, 2014