我开发了一个 android 应用程序,它将拍摄一个数字的照片并将其发送到服务器。在服务器中,图像将通过神经网络识别数字并将结果发回。我收到错误 500 而不是结果。
这是我的android代码:
//sendbmp is the photo taken from the camera. Its file type is .bmp
sendbmp = Tools.getFocusedBitmap(getApplicationContext(), camera, data, focusBox.getBox());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
jpgbitmap = sendbmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byteArray = stream.toByteArray();
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
mJSONArray = new JSONArray(byteArray);
base64array = Base64.encodeToString(byteArray,Base64.DEFAULT);
}
} catch (JSONException e) {
e.printStackTrace();
}
new Networkconnection().execute();
这是 Networkconnection() 的代码,这是我将照片发送到服务器的地方。我正在使用 okhttp:
private class Networkconnection extends AsyncTask<Void, Void, String> {
String result;
String new_result;
@Override
protected String doInBackground(Void... params) {
Response response;
OkHttpClient client = new OkHttpClient();
String byteValue = String.valueOf(base64array);
RequestBody body = RequestBody.create(MediaType.parse("json"), base64array);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
try {
response = client.newCall(request).execute();
result = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
这是我使用烧瓶的服务器端:
@app.route('/', methods=['GET','POST'])
def hello_world():
received_img = request.args.get('body')
decode_Imge = pic.open(BytesIO(base64.b64decode(received_img)))
result = Net.image_function(decode_Imge)
return result
if __name__ == '__main__':
Net = Network([784, 100,10])
for x in range(0,4):
training_data, validation_data,test_data = load_data_wrapper()
Net.SGD(training_data, 30, 10, 5.0, test_data = test_data)
app.run(host ="MyIP") //In my code I actually have my ip address and not "MYIP"
注意:当我运行服务器时,我没有收到任何错误。所有类都在服务器的一个文档中。当我打印回溯时,我得到以下信息:
Traceback (most recent call last): File "C:\Python27\lib\site-packages\werkzeug\serving.py", line 648, in inner fd = int(os.environ['WERKZEUG_SERVER_FD']) File "C:\Python27\lib\os.py", line 425, in __getitem__ return self.data[key.upper()] KeyError: 'WERKZEUG_SERVER_FD'