Код службы API выглядит следующим образом:
Код: Выделить всё
app = Flask(__name__)
CORS(app)
api = Api(app)
basedir = os.path.abspath(os.path.dirname(__file__))
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + os.path.join(
basedir, "instance", "database.db"
)
db = SQLAlchemy(app)
"""
API CODE BLAH BLAH
"""
api.add_resource(Lincenses, "/licenses/")
api.add_resource(Subjects, "/subjects//")
api.add_resource(
QuestionBank, "/questionbank///"
)
api.add_resource(GenerateQuizData, "/generatequizdata/")
@app.route("/")
def home():
return "api.py"
if __name__ == "__main__":
with app.app_context():
db.create_all()
app.run(host="0.0.0.0", port=5000, debug=True)
Код: Выделить всё
const [availableLicenses, setAvailableLicenses] = useState(null);
const [selectedLicense, setSelectedLicense] = useState("none");
useEffect(() => {
async function fetchAvailableLicenses() {
try {
const response = await fetch("http://192.168.0.195:5000/licenses/");
const availableLicenses = await response.json();
console.log(availableLicenses);
setAvailableLicenses(availableLicenses.Data);
} catch (error) {
console.error("Fetch error:", error);
}
}
fetchAvailableLicenses();
}, []);
Консоль.error("Fetch error:", error) просто выводит: ERROR Fetch error: [TypeError: Network request error] .
Я спрашиваю Gemini, что делать, чтобы решить эту проблему, и он сказал мне добавить flask-cors в мой API и использовать CORS(app), как показано выше, но это ничего не сделал.
Кроме того, когда я запустил npx expo start, он выдал мне следующее предупреждение:
Код: Выделить всё
The following packages should be updated for best compatibility with the installed expo version:
expo@55.0.5 - expected version: ~55.0.15
expo-constants@55.0.7 - expected version: ~55.0.14
expo-font@55.0.4 - expected version: ~55.0.6
expo-linking@55.0.7 - expected version: ~55.0.13
expo-router@55.0.5 - expected version: ~55.0.12
expo-status-bar@55.0.4 - expected version: ~55.0.5
react-native@0.83.2 - expected version: 0.83.4
Your project may not work correctly until you install the expected versions of the packages.
Если кто-нибудь сможет обнаружить проблему и помочь мне, я буду очень благодарен. я полностью застрял и не могу продолжать работу над проектом.