When I try to post data with axios it gives a network error without any information. I'm using python fast api as the backend and it works fine. I also tried to change my network address from ip address to localhost address but it also didn't work.
error log
LOG [AxiosError: Network Error]
LOG [AxiosError: Network Error]
LOG [AxiosError: Network Error]
LOG [AxiosError: Network Error]
react native code
const handleSubmit = () => {
const params = {
id,
month,
day,
time,
};
axios
.post("https://0.0.0.0:8080/prediction", params)
.then((res) => {
const data = res.data.data;
const parameters = JSON.stringify(params);
const msg = `Parameters: ${parameters}\nPrediction: ${data.prediction}`;
alert(msg);
})
.catch((error) => console.log(error));
};
return (
<View style={styles.view1}>
<Text style={{ textAlign: "center" }}>Time predictor</Text>
<View style={styles.inputview}>
<TextInput label="ID" value={id} onChangeText={(text) => setId(text)} />
</View>
<View style={styles.inputview}>
<TextInput
label="Month"
value={month}
onChangeText={(text) => setMonth(text)}
/>
</View>
<View style={styles.inputview}>
<TextInput
label="Day"
value={day}
onChangeText={(text) => setDay(text)}
/>
</View>
<View style={styles.inputview}>
<TextInput
label="Time"
value={time}
onChangeText={(text) => setTime(text)}
/>
</View>
<TouchableOpacity style={styles.btn} onPress={() => handleSubmit()}>
<Text style={styles.btnText}>Submit</Text>
</TouchableOpacity>
</View>
);
}
python code
@app.post("/prediction")
async def get_predict(data: Item):
feature_list = []
feature_list.append(int(data.id))
feature_list.append(int(data.month))
feature_list.append(int(data.day))
feature_list.append(int(data.time))
pred_value = prediction(feature_list)
return {
"data": {
'prediction': pred_value
}
}
if __name__ == '__main__':
uvicorn.run(app, port=8080, host='0.0.0.0')
Any help will be greatly appreciated.