Python, Flask, Gunicorn Error: Unrecognized Arguments
Asked Answered
M

4

11

I am running my app app.py using Python and Flask. I'm trying to deploy it to Heroku, and I followed the steps in this tutorial, including making a Procfile and requirements.txt. However, whenever I run heroku local, I get the following error:

web.1  | [2015-09-26 17:36:32 -0400] [19422] [INFO] Starting gunicorn 19.3.0
web.1  | [2015-09-26 17:36:32 -0400] [19422] [INFO] Listening at: http://0.0.0.0:5000 (19422)
web.1  | [2015-09-26 17:36:32 -0400] [19422] [INFO] Using worker: sync
web.1  | [2015-09-26 17:36:32 -0400] [19425] [INFO] Booting worker with pid: 19425
web.1  | usage: gunicorn [-h] [--auth_host_name AUTH_HOST_NAME]
web.1  | gunicorn: error: unrecognized arguments: app:app
web.1  | [2015-09-26 17:36:32 -0400] [19425] [INFO] Worker exiting (pid: 19425)

I've deployed apps successfully on Heroku before, but never have gotten this error. My Procfile is simply one line: web: gunicorn app:app.

Can anybody tell me how to fix this?

UPDATE: Modified some of my code and now when I run heroku local, it runs fine:

web.1  | [2015-09-28 18:52:13 -0400] [70650] [INFO] Starting gunicorn 19.3.0
web.1  | [2015-09-28 18:52:13 -0400] [70650] [INFO] Listening at: http://0.0.0.0:5000 (70650)
web.1  | [2015-09-28 18:52:13 -0400] [70650] [INFO] Using worker: sync
web.1  | [2015-09-28 18:52:13 -0400] [70653] [INFO] Booting worker with pid: 70653

However, when I deploy my Heroku app, I get an Application Error, and when I check the logs, I see the same error as before:

2015-09-28T22:50:54.775077+00:00 app[web.1]: 2015-09-28 22:50:54 [3] [INFO] Starting gunicorn 18.0
2015-09-28T22:50:54.776176+00:00 app[web.1]: 2015-09-28 22:50:54 [3] [INFO] Using worker: sync
2015-09-28T22:50:54.776052+00:00 app[web.1]: 2015-09-28 22:50:54 [3] [INFO] Listening at: http://0.0.0.0:24995 (3)
2015-09-28T22:50:54.786067+00:00 app[web.1]: 2015-09-28 22:50:54 [9] [INFO] Booting worker with pid: 9
2015-09-28T22:50:56.004336+00:00 heroku[web.1]: State changed from starting to up
2015-09-28T22:51:42.659042+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/" host=bobawithjames.herokuapp.com request_id=1afab4c0-484e-456b-be05-3086ee0711cd fwd="160.39.250.29" dyno=web.1 connect=1ms service=39ms status=503 bytes=0
2015-09-28T22:51:42.604331+00:00 app[web.1]:                 [--noauth_local_webserver]
2015-09-28T22:51:42.604323+00:00 app[web.1]: usage: gunicorn [-h] [--auth_host_name AUTH_HOST_NAME]
2015-09-28T22:51:42.604335+00:00 app[web.1]:                 [--auth_host_port [AUTH_HOST_PORT [AUTH_HOST_PORT ...]]]
2015-09-28T22:51:42.633611+00:00 app[web.1]: gunicorn: error: unrecognized arguments: hello:app

Anyone know what's going on now?

Maybellmaybelle answered 26/9, 2015 at 21:41 Comment(7)
try to rename your file to main.py and change Procfile to: web: gunicorn main:appDobbins
@Dobbins I tried that and got the same error. Any other suggestions?Maybellmaybelle
I'm having the same issue - anyone have a fix?Maragretmarala
In your procfile, where do you specify the log flag?Crambo
@GamesBrainiac I didn't specify the log flag - should it make a difference? I tried adding the flag and I still get the error.Maybellmaybelle
Is it possible that I'm missing certain dependencies? Right now my requirements.txt has the following: Flask==0.10.1 Jinja2==2.7.1 Werkzeug==0.9.4 gunicorn==18.0Maybellmaybelle
I had this same problem, it ended up that I had ArgumentParser attempting to get arguments from CLI - I commented that out and it works.Caller
M
4

I managed to solve my problem, with the suggestion that @euxneks proposed, as well as some messing around with Google OAuth 2.0.

Essentially, the tutorial that I had been using, Python Quickstart for Google Calendar API, was using argparse to get flags for credentials. However, it was also calling tools.run, which is deprecated. So instead, I decided to follow a different, more up-to-date tutorial, which walks you through using OAuth 2.0 with a Python Web App.

Maybellmaybelle answered 10/10, 2015 at 0:18 Comment(0)
M
23

I was able to solve this problem by replacing args = parser.parse_args() in my app with args, unknown = parser.parse_known_args()

Moderation answered 27/11, 2019 at 10:18 Comment(1)
Actually this solved my problem with Flask on GAE thanks hero.Cas
P
5

The issue was with having argparse in my script that is being ran by flask/gunicorn. Put these inside a:

if __name__ == "__main__":
    import argparse
    ...

This way if it's ran directly you can still parse the arguments running it standalone.

Piscator answered 26/11, 2019 at 17:7 Comment(0)
M
4

I managed to solve my problem, with the suggestion that @euxneks proposed, as well as some messing around with Google OAuth 2.0.

Essentially, the tutorial that I had been using, Python Quickstart for Google Calendar API, was using argparse to get flags for credentials. However, it was also calling tools.run, which is deprecated. So instead, I decided to follow a different, more up-to-date tutorial, which walks you through using OAuth 2.0 with a Python Web App.

Maybellmaybelle answered 10/10, 2015 at 0:18 Comment(0)
C
1

I was running into the same issue when following the tutorial. I removed the --log-file flag shown in their example. In addition, I also modified the string so it references the wsgi.py application under my app directory [/app/wsgi.py] as follows:

web: gunicorn app.wsgi

Hope this helps!

Consist answered 4/6, 2018 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.