python - Requests not able call multiple routes in same Flask application -


i not able use python requests call second route in same application using flask. know best practice call function directly, need call using url using requests. example:

from flask import flask import requests app = flask(__name__)  @app.route("/") def hello():     return "hello world!"  # works  @app.route("/myrequest") def myrequest():     #r = requests.get('http://www.stackoverflow.com', timeout=5).text  # works, external     #r = hello()  # works, need requests work     r = requests.get('http://127.0.0.1:5000/', timeout=5).text  # not work - requests.exceptions.timeout     return r  if __name__ == "__main__":     app.run(debug=true, port=5000) 

your code assumes app can handle multiple requests @ once: initial request, plus request generated while initial being handled.

if running development server app.run(), runs in single thread default; therefore, can handle 1 request @ time.

use app.run(threaded=true) enable multiple threads in development server.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -