Python, Flask, Gunicorn Error: Unrecognized Arguments

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


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.


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.