I'm writing a flask application, and within the application is a Dash dashboard, and inside one of its callbacks I'm attempting to access an API endpoint developed in the larger flask project.
The API endpoint works correctly when tested in the browser, but if I run: requests.get(url="http://192.168.X.X:5000/api/v1/search", params=params)
I get the following error:
HTTPConnectionPool(host='192.168.X.X', port=5000): Max retries exceeded with url: /api/v1/search (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001A17D8DBB50>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
This is the function I'm using to deliver the API results:
@bp.route('/v1/search', methods=['GET'])
def search_prediction():
info_dict = dict(
city = request.args['city'],
subject_age = int(request.args['subject_age']),
subject_race = request.args['subject_race'],
subject_sex = request.args['subject_sex'],
reason_for_stop = request.args['reason_for_stop'],
hour = int(request.args['hour']),
dayofweek = int(request.args['dayofweek']),
quarter = int(request.args['quarter'])
)
sample = pd.DataFrame(info_dict, index=[0])
info_dict['proba'] = float(stop_search_mod.predict_proba(sample)[0][1])
info_dict['outcome'] = 'search'
return jsonify(info_dict)
My config.py file looks like this:
from os import environ, path
from dotenv import load_dotenv
BASE_DIR = path.abspath(path.dirname(__file__))
load_dotenv(path.join(BASE_DIR, ".env"))
class Config:
"""Flask configuration variables."""
# General Config
FLASK_APP = environ.get("FLASK_APP")
FLASK_ENV = environ.get("FLASK_ENV")
SECRET_KEY = environ.get("SECRET_KEY")
# Static Assets
STATIC_FOLDER = "static"
TEMPLATES_FOLDER = "templates"
COMPRESSOR_DEBUG = environ.get("COMPRESSOR_DEBUG")
When I ping the URL in my browser with parameters arguments added in I get the correct result:

import requests from requests.adapters import HTTPAdapter sess = requests.Session() sess.mount('http://', HTTPAdapter(max_retries=5)) res=sess.get("http://someendpoint/")