tleyden / open-ocr

Run your own OCR-as-a-Service using Tesseract and Docker
Apache License 2.0
1.33k stars 223 forks source link

Internal Server Error : code 500 #62

Closed LeoLeon91 closed 7 years ago

LeoLeon91 commented 8 years ago

Hi, I installed openocr on Ubuntu on my laptop and tested the API with curl and it works perfect.

But I'm trying to create an android app which uploads file to openocr and gets back the text. But i'm getting this response from the server: SERVER RESPONSE: Response{protocol=http/1.1, code=500, message=Internal Server Error, url=http://192.168.0.102:8080/ocr-file-upload}

Please can you help with this, I'm trying this from 3-4 day and I'm still not able to get it work.

I'm using okHttp library to make the request and following is my code:

    public void doRequest() throws Exception {

        String BOUNDRY = "---BOUNDARY";
        StringBuffer requestBodyString = new StringBuffer();
        requestBodyString.append(BOUNDRY);
        requestBodyString.append("Content-Type: application/json");
        requestBodyString.append('\n');
        requestBodyString.append("{\"engine\":\"tesseract\"}");
        requestBodyString.append(BOUNDRY);
        requestBodyString.append('\n');
        requestBodyString.append(BOUNDRY);
        requestBodyString.append("Content-Disposition: attachment;");
        requestBodyString.append("Content-Type: image/png");
        requestBodyString.append("filename=\"attachment.txt\".");
        requestBodyString.append('\n');
        requestBodyString.append(new String(getBytesFromFile(uploadFile1)));
        requestBodyString.append(BOUNDRY);

        String reqBody = requestBodyString.toString();
        RequestBody requestBody = RequestBody.create(null, reqBody);

        final Request request = new Request.Builder().addHeader("Content-Type", "multipart/related").addHeader(" boundary", "---BOUNDARY")
                .url(serverUrl)
                .post(requestBody)
                .build();

        client.newCall(request).enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
                Log.v("MainActivity", "FAILED: " + e.getMessage());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.v("MainActivity", "SERVER RESPONSE: " + response.toString());
            }

        });

        //Response response = client.newCall(request).execute();
        // if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

    }//end do request

Please can you help in finding an error in this code, or provide a better code for android. Thanks!

tleyden commented 8 years ago

I think the best way to debug this would be to:

tleyden commented 8 years ago

If you can collect the server logs, it might reveal something.

If you started it via docker-compose, you can just run:

$ docker logs dockercompose_openocr_1

otherwise you'll need to find the container id with docker ps

$ docker ps  
$ docker logs <container-id>
tleyden commented 8 years ago

Another approach might be to ask on the OkHttp stack overflow

This line looks suspect to me:

requestBodyString.append(new String(getBytesFromFile(uploadFile1)));
tleyden commented 7 years ago

Closing due to inactivity. Doesn't look like an openocr issue