Home » Java » java – Getting Unexpected response code 500 on Volley using Pythonanywhere server-Exceptionshub

java – Getting Unexpected response code 500 on Volley using Pythonanywhere server-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have an API called /callModel that I call by sending a JSON object and getting a string in return. This is a flask server that I hosted on pythonanywhere.com . I tried this API on PostMan and it seems to work.

enter image description here

However, when I call this code from my app, it gives me an Unexpected response code 500. I believe this could be related to the server. Any idea on what is wrong with my code? PS: ChatModel is just a class where I can store user input in, while chat is a list of type chatModel

Here is my code

String URL= "https://nadeentameesh14.pythonanywhere.com/callModel";

final RequestQueue requestQueue = Volley.newRequestQueue(MainActivity.this);

StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {

                Log.d("Response", response);

            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(MainActivity.this,error.toString(),Toast.LENGTH_LONG).show();
                Log.d("Error:",error.toString());
            }
        }){
    @Override
    protected Map<String,String> getParams(){
        Map<String,String> params = new HashMap<String, String>();
        ChatModel m = chat.get(chat.size() - 1);
        String message = m.getChatMessage();
        Log.i("message", message);
        params.put("message",message);


        return params;
    }


};

requestQueue.add(stringRequest);
How to&Answers: