Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python requests return 504 in localhost

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\n

While trying to retrieve the URL http://127.0.0.1:5000/:

\r\n
  • Connection refused
\r\n\r\n

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?

like image 694
Konstantin Rusanov Avatar asked Apr 06 '17 11:04

Konstantin Rusanov


1 Answers

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)
like image 107
Konstantin Rusanov Avatar answered Oct 10 '22 10:10

Konstantin Rusanov