I was running an example for Dash in python.
For first It worked fine, then after 2-4 example it shows me this error.
(dash) C:\Users\nayo9002\Desktop>python dash_app.py
Running on http://127.0.0.1:8050/
Debugger PIN: 761-866-226
Serving Flask app "dash_app" (lazy loading)
Environment: production
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
Debug mode: on
Running on http://127.0.0.1:8050/
Debugger PIN: 288-266-928
I want to change this Production environment to Development. How should I proceed?
In windows :
FLASK_ENV=development
In Linux :
export FLASK_ENV=development
Related
I am not able to run Flask on host 0.0.0.0.
When I run it with 0.0.0.0, it instead shows my Local IP address.
* Serving Flask app 'application.py' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://192.168.86.147:5000/ (Press CTRL+C to quit)
Thanks
For an externally visible server on Flask, the documentation asks to run flask run --host=0.0.0.0 with the expectation being to see
$ flask run
* Running on http://127.0.0.1:5000/
However you might see your local IP.
As long as you can connect to that IP internally as well as externally, it should work as expected.
This question already has an answer here:
How does docker network work?
(1 answer)
Closed 1 year ago.
I have created a flask api and hosted it as a docker image. The dockerfile of the image looks like this:
FROM pymesh/pymesh:latest
WORKDIR /apiapp
RUN pip install flask
EXPOSE 5000
COPY . /apiapp
ENV FLASK_APP=feature_extract_api.py
# ENTRYPOINT ['/bin/bash']
CMD ["flask", "run", "--host", "0.0.0.0"]
The app.run() inside the original python file looks like this:
if __name__=='__main__':
app.run()
The terminal while running the docker container shows this:
(dockerenv) D:\Siemens\Docker Pymesh API>docker run -p 5000:5000 pymeshapi:trial
* Serving Flask app 'feature_extract_api.py' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://172.17.0.2:5000/ (Press CTRL+C to quit)
However, when I go to the link http://172.17.0.2:5000/, I get no response. But when I run
http://localhost:5000/, I get a valid response.
Why is this happening?
Thank You
The 'trick' with using the bridge network IP address doesn't work on Windows, due to how it runs Docker.
The recommended way is to map the port and use localhost.
When I try to run a script on Flask using Python 3 (I'm trying to do the Quickstart), I do not get a server, instead I get this -
(base) Marcs-Air:~ marcholder$ FLASK_APP=hello.py flask run
* Serving Flask app "hello.py"
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Error: Could not import "hello"
Any help to fix this is much appreciated!
im trying to run flask and when i run
flask run
I get this error
(snoop) ether#ether:~/Documents/loginsystem$ flask run
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
Usage: flask run [OPTIONS]
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.
I have done
Run command: set FLASK_APP=main.py
Run command: set FLASK_DEBUG=1
Run command: flask run
but that doesn't change anything on the error
Im using this tutorial for a login system
https://codeshack.io/login-system-python-flask-mysql/
Can you try exporting the variable instead of just setting it ?
export FLASK_APP=main.py
and not
set FLASK_APP=main.py
I have a flask app that runs a couple of things based on the user call. In this app, I also have one basic endpoint that just returns a string which would help me to see if the app is running or not.
#app.route("/hello")
def hello():
return "Hello World!"
Now I tried to dockerize this app using this tutorial from the official docker site. The flask app listens on the port 5000 and so I added an entry in my Dockerfile to expose the port 5000.
EXPOSE 5000
And the command that I am using in the Dockerfile to run the app is
CMD ["python","model.py"]
model.py file has the flask code that calls other functions based on the user input.
Now when I run my app after containerizing it, I see the required output on the terminal that the flask app is indeed running. This is the command that I used to run the app.
docker run -p 5000:5000 firstContainer
When I try to call the basic helloWorld method above by using the request http://localhost:5000/hello, I get an error message saying that the site is unavailable. Is there anything that I am doing wrong wrt the port mappings here? How do I fix this issue ?
EDIT: Adding more details
So I tried to go into the container to see what's happening and I was able to view the files that were available on the container and they look good. When I tried to start the app again in the container using the base command
python model.py
it returned an error saying that the port is already in use. So this should mean that the app is indeed listening on the port. I also installed curl inside the container to browse the URL and it returned the expected string when I ran it inside the container. I just don't understand how I can expose it to outside world
EDIT 2:
Container logs
* Serving Flask app "model" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
The problem is the server defaults to answer internal requests only. You have two options.
You can set the host programatically to:
0.0.0.0
Use the CMD:
flask run --host=0.0.0.0`
Tip: There is also a container running flask behind ngnix out-of-the-box.
try this :
docker run --rm -it --network=host -p 5000:5000 firstContainer
the problem is probably related to networking. so --network=host connects the container to underlying host.
I have the same issue on my Flask App in the docker container. I have used --network=host and resolved the issue.
# docker run -it -p 8080:8080 --network=host mbilgen/metacriticv3:1.0
WARNING: Published ports are discarded when using host network mode
* Serving Flask app "main" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:8080/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 258-420-336
127.0.0.1 - - [12/May/2019 03:55:08] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [12/May/2019 03:55:13] "GET /games HTTP/1.1" 200 -
INFO:werkzeug:127.0.0.1 - - [12/May/2019 03:55:13] "GET /games HTTP/1.1" 200 -