0
votes

I am using python+webapp2 for my backend code. The POST method looks like::

class SendOTP(BookSearchRequestHandler):
    def post(self):

        phone_no = self.request.get('phno').rstrip()
        uuid = self.request.get('uuid').rstrip()
        //some operations

        //construction of JSON
        tpl_values = {
        'books': book1_list,
        'query': search_query,
        'is_logged':is_logged,
        'is_ipsame':is_ipsame
         }

       self.render('serp/products.html', **tpl_values)

This works very well with my front-end html code. I can POST values and then render another page with contents of tpl_values.

However, now I am developing android app. The android app expects to send and receive data in JSON format. The code self.request.get() cannot read the values sent by POSTMAN POST. I get 405 method not allowed, The method GET Not Allowed. Also self.render cannot be used to send data to android.

<html>
    <head>
        <title>405 Method Not Allowed</title>
    </head>
    <body>
        <h1>405 Method Not Allowed</h1>
  The method GET is not allowed for this resource.
        <br />
        <br />
    </body>
</html>

How can I modify the code so that it serves requests from both html and android , POSTMAN? Thanks

1

1 Answers

2
votes

The error indicates that the request received is a GET, not a POST and you handler doesn't have a .get() method registered. To confirm you can temporarily add a .get() method to your handler in which you should be able to read the request message body (or at least you'd get a different error message, for whatever other reason).

Check your android code and make sure you're sending a POST request instead of a GET.