Im trying to deploy a python app to heroku. I use a web framework called quart (an asyncio adaptation of flask). The build succeeds when I try to deploy, but in the heroku logs, I get this error message:
TypeError: __call__() takes 1 positional argument but 3 were
This is the code that runs the app:
if __name__ == '__main__':
app.run(host='0.0.0.0', port=int(os.environ['PORT']))
My procfile consists of this:
web: gunicorn main_loop:app
Help would be appreciated.
Quart requires a specific Gunicorn worker class1. I think if your procfile was
web: gunicorn --worker-class quart.worker.GunicornWorker main_loop:app
it would work. (I don't have a heroku dyno available to test though).
(I am the Quart author)
Related
I'm trying to deploy a Flask app to Heroku.
When I run it locally, it works fine.
But when I deploy it to Heroku and start the dyno, it crashes.
It seem to have a problem with the relative parent package:
The project structure is as follows:
My Procfile is as follows:
web: gunicorn app:app --log-file=-
And this is the line it crashes at:
Why it fails to see that parent package?
Thanks in advance!
I've got an aiohttp based project in Python, not overly complicated, just takes advantage of the async routes, etc. I'd like to quickly deploy to Heroku and cannot find a recent step by step. I've tried using their standard Gunicorn approach and it's not working. My Procfile is:
web: gunicorn go:web --preload
Here are the errors that seem to be important from my Heroku log:
2020-06-28T01:37:40.103872+00:00 app[web.1]: ======== Running on http://0.0.0.0:8080 ========
2020-06-28T01:37:40.103895+00:00 app[web.1]: (Press CTRL+C to quit)
2020-06-28T01:37:51.000000+00:00 app[api]: Build succeeded
2020-06-28T01:38:31.441039+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
If anyone has successfully deployed an aiohttp project to Heroku, I'd love to know what you had to adjust to get it working! Thanks very much.
I got this working for a hello world aiohttp app
here's app.py
from aiohttp import web
import os
async def hello(request):
return web.Response(text="Hello, world")
app = web.Application()
app.add_routes([web.get('/', hello)])
web.run_app(app, port=os.getenv('PORT'))
Procfile
web: python app.py --bind localhost:8080
requirements.txt
aiohttp
Flask
Werkzeug
Thankful for this other SO post which help alot for not using gunicorn.
BAMN!
I am trying to run a aiohttp based server using Gunicorn.
Here is the command:
gunicorn aiohttpdemo_polls:app --bind 127.0.0.1:8080
It returns:
Failed to find application: 'aiohttpdemo_polls'
But when I am running it using python -m like below:
python -m aiohttpdemo_polls
It works fine. The code can be found from here which is a demo app in the aiohttp repo.
Also tried it like below:
gunicorn aiohttpdemo_polls.main:app --bind 127.0.0.1:8080
But its also not running the server. It returns
Failed to find application: 'aiohttpdemo_polls.main'
Any idea where to look further for fixing the issue?
aiohttp 3.1 supports coroutine as application factory, such as:
async def my_web_app():
app = web.Application()
app.router.add_get('/', index)
return app
Current implementation of aiohttpdemo_polls uses this approach. It can be started with
gunicorn aiohttpdemo_polls.main:init_app --bind localhost:8080 --worker-class aiohttp.GunicornWebWorker
The demo does not support gunicorn yet.
I filed an issue: https://github.com/aio-libs/aiohttp-demos/issues/10
Thanks for report.
When i'm runing heroku ps:scale web=1, I'm getting below error.
Scaling dynos... failed
No such process type web defined in Procfile.
My Procfile contains below code.
worker: python vot.py
I also did heroku run bash and the Procfile is there and file name is also correct.
How could i solve this ?
Your heroku command has "web=1" but your Procfile has "worker". Try:
heroku ps:scale worker=1
I dont see you define single process type "web" in your procfile.
Follow on this heroku procfile and define python procfile
:
web: gunicorn gettingstarted.wsgi --log-file -
This declares a single process type, web, and the command needed to run it. The name web is important here. It declares that this process type will be attached to the HTTP routing stack of Heroku, and receive web traffic when deployed.
Procfiles can contain additional process types.
worker: bundle exec rake jobs:work
My question is basically what's in the title: how can I setup gunicorn to run a web.py app? (Also, if there are any differences, how would I do it on heroku?)
I already have my app running on heroku using the built in cherrypy, but I have not been able to get gunicorn to work with web.py (I just have no idea where to start - I couldn't find any tutorials).
I'm afraid I'm not familar with Heroku, but I can answer your basic question.
gunicorn is a HTTP server for running Python web apps via WSGI. web.py is a framework for creating Python web apps using WSGI.
So you don't really need a tutorial for using both together, as all you need to do is figure out how to pass the WSGI entry point of your web.py application to gunicorn. A WSGI application is just a Python callable with the right interface i.e. it takes certain parameters and returns a certain response. See this WSGI tutorial for more.
The "hello world" application from the web.py tutorial looks like this test.py:
import web
urls = (
'/', 'index'
)
class index:
def GET(self):
return "Hello, world!"
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
But that does not expose the WSGI application which gunicorn needs.
web.py provides a WSGI application via the wsgifunc method of web.application. We can add this to test.py by adding the following after the index class:
# For serving using any wsgi server
wsgi_app = web.application(urls, globals()).wsgifunc()
This is basically what the web.py documentation tells you to do in the deployment section, when using Apache + mod_wsgi - the fact that the Python code is the same for us with gunicorn is not a coincidence because this is exactly what WSGI gives you - a standard way to write the Python so that it can be deployed using any WSGI capable server.
As explained in the gunicorn docs, we can then point gunicorn at the wsgi_app member of the test module as follows:
(tmp)day#office:~/tmp$ gunicorn test:wsgi_app
2012-12-03 23:31:11 [19265] [INFO] Starting gunicorn 0.16.1
2012-12-03 23:31:11 [19265] [INFO] Listening at: http://127.0.0.1:8000 (19265)
2012-12-03 23:31:11 [19265] [INFO] Using worker: sync
2012-12-03 23:31:11 [19268] [INFO] Booting worker with pid: 19268