python – BadValueError thrown when entering Integer in html form-ThrowExceptions

Exception or error:

I’m working with Python to create a Google App Engine application.To test my app, i am using html forms to enter data.
In my form i have a line:

<tr><td>Age</td><td><input type="number" size="10" name="age"/></td></tr>

and in my model class, a property defined like this:

class Person(ndb.Model):
age = ndb.IntegerProperty()

when i test my app locally it displays the form but on entering a value for age, i get a BadValueError: Expected integer, got u '23' message.Posting image because i do not know how to copy command prompt text.I hope it’s clear enough.

enter image description here

Edit: This is how the data is been passed from html form.

  # Data taken from the registration form (above) is used to 
  # create a new member.
 class PersonHandler(webapp2.RequestHandler):

 def post(self):
    # need to check this member-name does not exist
    name = self.request.get('name')
    callback = self.request.get('callback')
    member = Member.get_by_id(name)
    if member:           # This member name already exists.
        self.error(409)  # This is the HTTP status code for 'unable to process due to conflict'
        a = self.request.get("age")

        member = Member(age=a,...)
        if callback:
            self.response.write(callback + '(' + member.toJSON + ')')

Can someone tell me what am doing wrong?

How to solve:

You simply need to convert the retrieved value to an integer:

        a = int(self.request.get("age"))

Leave a Reply

Your email address will not be published. Required fields are marked *