i have a little Flask app inside a docker.
I want that my flask app auth with my bank account, therefore a package (dkb_robo) is provided and its nice.
But my Bankaccount requiers a TAN from my mobile phone i need to pass through to standart input. dkb_robo somewhere ask with self.dkb_br["tan"] = input("TAN: ")
I want to pass this TAN from the frontend of a flask site. Any idea how to start here?
While googling i just found stuff like this but its aint working :(
app = Flask(__name__)
#app.route('/')
def tutorialspoint():
sys.stdin = StringIO.StringIO('123456')
return 'Hello asasas'
#app.route('/login/')
def tutorialspoint1():
with DKBRobo("username", "password", True, False) as dkb:
print(dkb.last_login)
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
Related
I am trying to host a flask server from my windows computer so I can access it from external devices
I am using Flask/Python and have already tried a few things but can't get it to work
Tried running it on 0.0.0.0, port 33, 5000, etc. but I still can't access it this way
from flask import Flask, request, abort
app = Flask(__name__)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=33)
When I then run the file I get:
Running on http://0.0.0.0:33/ (Press CTRL+C to quit)
But it isn't even running there, nor on any other way I can access it
I expect to be able to access my flask application and send requests to it by using my public IP address
What can I do here to make it work?
You have missed an important line in your code:
After the line
app = Flask(__name__)
You have to write the line:
#app.route('/')
We use the route() decorator to tell Flask what URL should trigger our function.
And then define a function that will tell what task to be performed in the web app hosted in the respective address.
The function might look something like this:
def hello_world():
return 'Hello, World!'
The complete code then will look like:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=33)
Hope this helps.
I'm newbie in Flask. I'm using stackoverflow for study , and please dont dislike this question a lot and dont take away my ability to ask questions and learn.
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello_world():
return 'Hello World'
if __name__ == '__main__':
app.run()
After changing 'Hello World' to any other string the information on server dont changes after runing my new code. what i am doing wrong?
Assuming that you are using the python dev webserver (calling your script from command line), I would have to ask you if after the change, have you stopped the script and started again. If not, you should try do that.
Another alternative is to do a small change in your script, as in below:
from flask import Flask
app = Flask(__name__)
#app.route('/')
def hello_world():
return 'Hello World'
if __name__ == '__main__':
app.run(debug=True)
The debug flag should help your web server to detect changes in the code.
I would also recommend that you go over this tutorial, to help you to decrease the learning curve:
https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
Miguel is a reference on Flask community.
I trained a machine learning model which I wanted to deploy as an app. I learnt that flask is especially suited for this.
I have two functions, get_data from the user of the web app and then, infer_results which prints the results of image type.
I am trying to set up flask for the above use case. I started by following this tutorial: https://sourcedexter.com/python-rest-api-flask/
What I did:
In [71]: app = Flask(__name__)
In [72]: #app.route("/me", methods=["GET"])
...: def get_results():
...: return "Dummy Result"
And then,
In [73]: app.run(host="0.0.0.0", threaded=True)
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
But all I get is:
I can't figure out what is going wrong? This is my main question.
On a sidenote, it would be really great if you could offer some advice or suggestion on : how should I go about building my app: I want to do in Python only. But then, how should I design the UI: where user can put his data and upload it? Is there a way to package all my code (the machine learning code + the user input/output) in a desktop application that user can download and run on his PC?
Instead of app.run(host="0.0.0.0", threaded=True)
Use:
app.run(host="localhost", threaded=True)
Or Execute the below script:
from flask import Flask, render_template
app = Flask(__name__)
# index
#app.route('/')
def index():
return "Hello"
# /me
#app.route("/me", methods=["GET"])
def get_results():
return "Dummy Result"
if __name__ == "__main__":
app.run()
I'm working through RealPython and I'm having trouble with the flask dynamic route.
Everything seemed to work until the dynamic route. Now if I try to enter a "search query" (i.e. localhost:5000/test/hi) the page is not found. localhost:5000 still works fine.
# ---- Flask Hello World ---- #
# import the Flask class from the flask module
from flask import Flask
# create the application object
app = Flask(__name__)
# use decorators to link the function to a url
#app.route("/")
#app.route("/hello")
# define the view using a function, which returns a string
def hello_world():
return "Hello, World!"
# start the development server using the run() method
if __name__ == "__main__":
app.run()
# dynamic route
#app.route("/test/<search_query>")
def search(search_query):
return search_query
I can't see that other people using RealPython have had an issue with the same code, so I'm not sure what I'm doing wrong.
The reason why this is not working is because flask never learns that you have another route other / and /hello because your program gets stuck on app.run().
If you wanted to add this, all you need to do would be to add the new route before calling app.run() like so:
# ---- Flask Hello World ---- #
# import the Flask class from the flask module
from flask import Flask
# create the application object
app = Flask(__name__)
# use decorators to link the function to a url
#app.route("/")
#app.route("/hello")
# define the view using a function, which returns a string
def hello_world():
return "Hello, World!"
# dynamic route
#app.route("/test/<search_query>")
def search(search_query):
return search_query
# start the development server using the run() method
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True, port=5000)
Now this will work.
Note: You don't need to change the run configurations inside of app.run. You can just use app.run() without any arguments and your app will run fine on your local machine.
Try using the entire URL instead of just the IP address.
Consider the following minimal working flask app:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "I am /"
#app.route("/api")
def api():
return "I am /api"
if __name__ == "__main__":
app.run()
This happily works. But when I try to make a GET request with the "requests" module from the hello route to the api route - I never get a response in the browser when trying to access http://127.0.0.1:5000/
from flask import Flask
import requests
app = Flask(__name__)
#app.route("/")
def hello():
r = requests.get("http://127.0.0.1:5000/api")
return "I am /" # This never happens :(
#app.route("/api")
def api():
return "I am /api"
if __name__ == "__main__":
app.run()
So my questions are: Why does this happen and how can I fix this?
You are running your WSGI app with the Flask test server, which by default uses a single thread to handle requests. So when your one request thread tries to call back into the same server, it is still busy trying to handle that one request.
You'll need to enable threading:
if __name__ == "__main__":
app.run(threaded=True)
or use a more advanced WSGI server; see Deployment Options.