title: Python requests.post calling own api function inside same Flask app
body: <p>My code is trying to check the login username and password, and if match, just send a new post request to localhost /api/homepage with data "values", I tried it in local virtual env of the python scripts and it works, but for production mode, after inputting the user name and password, 502 Bad Gateways occured. I have already imported 'requests' library.in Nginx setting no load balance is used.</p>
  
  <pre><code>@app.route('/api/login',methods=['GET', 'POST'])
  def login():
      username = request.form['usermail']
      pw = request.form['password']
      db=MySQLdb.connect("localhost","root","1234","4080")
      cursor = db.cursor()
      query = "select * from user where username='"+username+"' AND password='"+pw+"';"
      try:
          cursor.execute(query)
          result = cursor.fetchall()
      except:
          db.rollback()
          return query
  
     if len(result)==1:
  
         values ={'user':'wes'}
         r = requests.post('http://127.0.0.1/api/homepage' ,data=values)
         return  r.content
  
     else:
         return 'Fail login'
  
  @app.route('/api/homepage',methods=['POST'])
  def Display_Homepage():
      return request.form['user'];
  </code></pre>