CiscoDevNet / devnet-express-cc-issues

Suggested changes to the content of the learning labs for Devnet Express for Cloud Collab
MIT License
0 stars 0 forks source link

Environment variable for flask-api.py #19

Closed jbogarin closed 6 years ago

jbogarin commented 6 years ago

In the collab-tools-visual-studio-code-ide-itp and the related code in the flask-api.py, it needs an integer because that is what is expected by app.run() function.

The recommended change is something like this:

    default = int(os.getenv('PORT', 5000))
    app.run(port=default)

Without that change, python returns the following error message:

Traceback (most recent call last): File "flask-api.py", line 14, in app.run(port=default) File "/python/pyvenv36/lib/python3.6/site-packages/flask/app.py", line 841, in run run_simple(host, port, self, **options) File "/python/pyvenv36/lib/python3.6/site-packages/werkzeug/serving.py", line 748, in run_simple raise TypeError('port must be an integer') TypeError: port must be an integer

dstaudt commented 6 years ago

Looks like this may have been corrected, as the current sample code repo shows an integer being provided: https://github.com/CiscoDevNet/devnet-express-cloud-collab-code-samples/blob/master/itp/collab-tools-visual-studio-code-ide-itp/flask-api.py

Can you try refreshing your sample code repo, and re-open this issue if you still see a problem?

jbogarin commented 6 years ago

@dstaudt I think I didn't make myself clear, right now the code says

default = os.getenv('PORT', 5000)

but when you define an environment variable, the environment variable is a string so that line fails.

The correct code should be:

default = int(os.getenv('PORT', 5000)) including the int before the os.getenv

dstaudt commented 6 years ago

Gotcha...I actually couldn't reproduce the problem as state on my system, however I made the change (committed) anyway as it should be more correct (new version also works on my system without issue.)