I run werkzeug server (via Flask) and trying to connect to localhost by requests lib and got 504 error, but if open http://127.0.0.1:5000/ in browser - anything ok.
My code:
import requests
r = requests.get('http://127.0.0.1:5000/')
print(r.content)
Response error:
b'\r\n\r\nERROR: Gateway Timeout\r\n
ERROR: Gateway Timeout
\r\n\r\n\r\nWhile trying to retrieve the URL http://127.0.0.1:5000/:
\r\n\r\n\r\n
- Connection refused
Your cache administrator is webmaster.\r\n\r\nGenerated Thu, 06 Apr 2017 11:31:09 GMT by 10.101.0.1 (Mikrotik HttpProxy)\r\n\r\n'
Flask code:
from flask import Flask, request, render_template, jsonify, Response
import geoLocation
import models
import json
from bson.json_util import dumps
from bson import json_util
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
return 'OK'
....
How to connect to localhost (ip + port) via requests lib?
Found solution, disable proxy
import os
import requests
os.environ['NO_PROXY'] = '127.0.0.1'
r = requests.get('http://127.0.0.1:5000')
print(r.content)