Run Python CGI Application on Heroku

♀尐吖头ヾ 提交于 2019-12-03 05:57:13

Heroku Cedar is centered around self-hosting web applications, so you need to be able to bundle your application together and run it as a single command.

I think the easiest way would be to port your application to Flask. It isn't very complicated, especially if it is only 2 or 3 scripts.

Another option (depending on your performance requirements) would be to use the simple CGI server in the Python standard library and the Python buildpack. I think you would need to bundle up your scripts in a ./cgi-bin directory and start the server (in the procfile) with:

 web: bin/python -m CGIHTTPServer $PORT

The most complex way would be to bundle lighttpd and your scripts together and write a shell script to start it all up. You would have to make sure your compiled binaries are compatible with Heroku. I would look at the PHP buildpack as a starting point.

I inquired with Heroku support about a cgi application that I tried to serve on Heroku's platform and here's the response:

Hello,

Unfortunately, we don't support CGI-style applications, only pure-Python ones. You may have some luck playing around with the Python CGIHTTPServer module some more, but if it doesn't suit your needs, you may be out of luck.

To add to the top answer, for Python 3 the command in the Procfile should be this.

web: python -m http.server --cgi $PORT
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!