i'm trying to make a simple request to Flask but i keep getting connection refused.
This is my main.py
import os
import sys
from konlpy.tag import Kkma, Hannanum, Okt
from flask import Flask, jsonify
sys.stdin.reconfigure(encoding="utf-8")
sys.stdout.reconfigure(encoding="utf-8")
app = Flask(__name__)
basedir = os.path.abspath(os.path.dirname(__file__))
@app.route('/', methods=["GET"])
def index():
return jsonify({'message': 'Hello, world!'})
if __name__ == '__main__':
app.run(debug=True)
I started and got this message
* Serving Flask app 'main'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
And on Flutter:
final String baseUrl = 'http://127.0.0.1:5000';
void _search() async {
try {
final response = await http.get(Uri.parse(baseUrl));
final data = jsonDecode(response.body);
print(data);
} catch (e) {
print(e);
}
}
I was reading this: why is flutter refusing to connect on localhost:8000 or 127.0.01:8000?
I'm using the android emulator, i also tried making the request to https://10.0.2.2:5000
, but still didn't work. I also tried on my real device and got the same thing.
My computer is connected to the internet via cable, so maybe that's something to consider.
Thanks