我正在構建一個應用程式,前面是 Flutter,后面是 python。我必須將資訊從flutter發送到python,例如:
{'english: 'Hello', 'hebrew':'????'}.
不幸的是,當我嘗試這樣做時,python 回傳 io.UnsupportedOperation: not writable.
這是我發送資訊的顫振代碼:
() async{
var encoded = utf8.encode(hebrewController.text);
Map<String, String> body = {'english': englishController.text, 'hebrew': encoded.toString()};
String jsonString = json.encode(body);
var response = await http.post(
Uri.parse("http://192.168.80.46:8080/add"),
body: jsonString,
encoding: Encoding.getByName('UTF-8')
);
if(response.statusCode == 200){
showSnackBar("Succesfully added new pair of words");
}else{
showSnackBar("Something went wrong...");
}
Navigator.of(context).pop();
}
順便說一句,我嘗試了 utf8.encode 和 utf8.encode,沒有任何效果。
這是接受的一面:
def add():
english_word = request.args.get("english")
hebrew_word = request.args.get("hebrew")
scripts.add(english_word, hebrew_word)
腳本.添加:
def add(w1, w2):
with open('data.csv') as f:
writer = csv.writer(f)
writer.writerow([w1, w2])
f.close
如何將 Unicode 發送到服務器端?
uj5u.com熱心網友回復:
io.UnsupportedOperation: not writable與unicode編碼無關。您需要在您的add函式中打開一個可寫檔案。open默認為只讀。我假設你也想附加到data.csv所以使用a標志。
def add(w1, w2):
with open('data.csv', 'a') as f:
writer = csv.writer(f)
writer.writerow([w1, w2])
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/372058.html
