Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8195991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:19:39+00:00 2026-06-07T05:19:39+00:00

Running the code bellow, I’m getting this error: Traceback (most recent call last): File

  • 0

Running the code bellow, I’m getting this error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1536, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1530, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\CG\Documents\ud\contract\main.py", line 81, in get
    numBook = contract.book_number
AttributeError: 'NoneType' object has no attribute 'book_number'

Since I’m putting this initial row in the bd Contract (as sugested here and others similar questions):

first_query = db.GqlQuery("SELECT * FROM Contract ORDER BY date DESC")
                if first_query is None: # Puting something in db if it's empty
                    first_record = Contract(book_number = 1, initial_page = 1, final_page = 1)
                    first_record.put()

I also make a test to verify if the query is returning none:

first_query = db.GqlQuery("SELECT * FROM Contract ORDER BY date DESC")
    if first_query is None: # Puting something in db if it's empty
        first_record = Contract(book_number = 1, initial_page = 1, final_page = 1)
        first_record.put()
    else:         
        numBook = 0
        numInitialPage = 0
        numFinalPage = 0

When I print this:
q = db.GqlQuery(“SELECT * FROM Contract ORDER BY date DESC”)

I get this:

When I print this:

contract = q.get()

I get None

How to fix that making put() work?

# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import os

import webapp2

import jinja2

jinja_environment = jinja2.Environment(autoescape=True,
    loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')))

import re

from google.appengine.ext import db

USER_RE = re.compile(r"^[a-zA-Z0-9_ -]{3,20}$")
def valid_person(person):
    return USER_RE.match(person)

PASS_RE = re.compile(r"^.{3,20}$")
def valid_SSN(SSN):
    return PASS_RE.match(SSN)

EMAIL_RE = re.compile(r"^[\S]+@[\S]+\.[\S]+$")
def valid_email(email):
    return EMAIL_RE.match(email)

import time

import datetime


def dateToday():
    today = datetime.datetime.today()
    todayDay = str(today.day)
    todayMonth = str(today.month)
    monthExt = {'1':' January ', '2':'February', '3':' March ', '4':'April', '5':'May', '6':'June', '7':' July ', '8':'August', '9':'September', '10':'October', '11':'November ', '12':'December'}
    todayYear = str(today.year)
    return(todayDay + ' of  ' + monthExt[todayMonth] + ' of ' + todayYear)

class Contract(db.Model):
    book_number = db.IntegerProperty(required = True)
    initial_page = db.IntegerProperty(required = True)
    final_page = db.IntegerProperty(required = True)
    date = db.DateTimeProperty(auto_now_add=True)

class MainHandler(webapp2.RequestHandler):
    def get(self):
        first_query = db.GqlQuery("SELECT * FROM Contract ORDER BY date DESC")
            if first_query is None: # Puting something in db if it's empty
                first_record = Contract(book_number = 1, initial_page = 1, final_page = 1)
                first_record.put()
        q = db.GqlQuery("SELECT * FROM Contract ORDER BY date DESC")
        contract = q.get() # return only the first entity
        numBook = contract.book_number
        numInitialPage = contract.initial_page
        numFinalPage = contract.final_page
        template_values = {"person": "",
                                       "nacionality": "",
                                       "SSN": "",
                                       "driverLicense": "",
                                       "email":"",
                                       "person_error": "",
                                       "SSN_error": "",
                                       "driverLicense_error": "",
                                       "address": "",
                                       "email_error": "",
                                       "numBook": numBook,
                                       "numInitialPage": numInitialPage,
                                       "numFinalPage": numFinalPage,
                                       }
        template = jinja_environment.get_template('index.html')
        self.response.out.write(template.render(template_values))

    def post(self):
        person_name = self.request.get("person")
        user_nacionality = self.request.get('nacionality')
        user_profession = self.request.get('profession')
        user_maritalStatus = self.request.get('maritalStatus')
        user_SSN = self.request.get('SSN')
        user_email = self.request.get('email')
        user_driverLicense = self.request.get('driverLicense')
        person_error = ""
        SSN_error = ""
        driverLicense_error = ""
        geted_email_error = ""
        address = self.request.get('address')
        contractType = self.request.get("contractType")
        owner = self.request.get("owner")
        witness = self.request.get("witness")
        numBook = self.request.get("numBook")
        numInitialPage = self.request.get("numInitialPage")
        numFinalPage = self.request.get("numFinalPage")

        if (person_name and valid_person(person_name)) and (user_SSN and valid_SSN(user_SSN)) and ((not user_email) or (user_email and valid_email(user_email))):
            a = Person(firstName = person_name,
                                   nacionality = user_nacionality,
                                   maritalStatus = user_maritalStatus,
                                   profession = user_profession,
                                   SSN = int(user_SSN),
                                   driverLicense = int(user_driverLicense)
                                   #address = user_address
                                   )
            a.put()
            self.redirect('/your_contract?person=%s&nacionality=%s&profession=%s&maritalStatus=%s&SSN=%s&driverLicense=%s&email=%s&witness=%s&owner=%s&contractType=%s&address=%s&numBook=%s&numInitialPage=%s&numFinalPage=%s' % (person_name, user_nacionality, user_profession, user_maritalStatus, user_SSN, user_driverLicense, user_email,
witness, owner, contractType, address, numBook, numInitialPage, numFinalPage))

        else:
            if not person_name or not valid_person(person_name):
                person_error = "Oh no!!! this person name isn't valid!"
            if not user_SSN or not valid_SSN(user_SSN):
                SSN_error = "Oh no!!! SSN isn't valid!"
            if user_email and not valid_email(user_email):
                geted_email_error = "Oh no!!! e-mail isn't valid!"
            template_values = {"person": person_name,
                                "nacionality": user_nacionality,
                                "maritalStatus": user_maritalStatus,
                                "profession": user_profession,
                                "SSN": user_SSN,
                                "driverLicense": user_driverLicense,
                                "email": user_email,
                                "person_error": person_error,
                                "SSN_error": SSN_error,
                                "driverLicense_error": user_driverLicense,
                                "address": address,
                                "email_error": geted_email_error}
            template = jinja_environment.get_template('index.html')
            self.response.out.write(template.render(template_values))

class your_contractHandler(webapp2.RequestHandler):
    def get(self):
        geted_person_name = self.request.get('person')
        geted_user_nacionality = self.request.get("nacionality")
        geted_user_profession = self.request.get("profession")
        geted_user_maritalStatus = self.request.get("maritalStatus")
        geted_user_SSN = self.request.get('SSN')
        geted_user_email = self.request.get('email')
        geted_user_driverLicense = self.request.get('driverLicense')
        geted_person_error = ""
        geted_SSN_error = ""
        geted_driverLicense_error = ""
        geted_address = self.request.get('address')
        geted_owner = self.request.get("owner")
        geted_witness = self.request.get("witness")
        geted_contractType = self.request.get("contractType")
        geted_dateToday = dateToday()
        your_contract = jinja_environment.get_template('your_contract.html')
        geted_numBook = self.request.get('numBook')
        geted_numInitialPage = self.request.get('numInitialPage')
        geted_numFinalPage = self.request.get('numFinalPage')

        contract = Contract(book_number = geted_numBook, initial_page = geted_numInitialPage, final_page = geted_numFinalPage)
        contract.put()

        your_contract_values = {"person":geted_person_name,
                                "nacionality":geted_user_nacionality,
                                "maritalStatus": geted_user_maritalStatus,
                                "profession": geted_user_profession,
                                "SSN":geted_user_SSN,
                                "driverLicense":geted_user_driverLicense,
                                "address":geted_address,
                                "email":geted_user_email,
                                "contractType":geted_contractType,
                                "dateContract":geted_dateToday,
                                "numBook":geted_numBook,
                                "numInitialPage":geted_numInitialPage,
                                "numFinalPage":geted_numInitialPage,
                                }
        template = jinja_environment.get_template('index.html')
        self.response.out.write(your_contract.render(your_contract_values))


class Contract(db.Model):
    book_number = db.IntegerProperty(required = True)
    initial_page = db.IntegerProperty(required = True)
    final_page = db.IntegerProperty(required = True)
    date = db.DateTimeProperty(auto_now_add=True)


app = webapp2.WSGIApplication([('/', MainHandler), ('/your_contract', your_contractHandler)],
                              debug=True)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:19:41+00:00Added an answer on June 7, 2026 at 5:19 am

    Try this:

    first_query = db.GqlQuery("SELECT * FROM Contract ORDER BY date DESC").get()
    

    You have to use get() to select the last record (and not the query object). So, the code will run inside the if block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this unfamiliar error when running the code bellow. I can't see
I get this message when running the code below: There is an error in
I am getting an argument of length zero after running the code below. I
While running the code I've included below I receive the error EntityCommandExecutionException was unhandled
I wanted to generate a list view using below code. But after running this
I'm running code that sometimes yields this: UInt32 current; int left, right; ... //sometimes
After running the code bellow, the item.Name still says New Item. what is wrong
I'm running the code below and getting an empty chart using Flot/jQuery. Ideally what
Running the code below gives me the error -bash: [: -ne: unary operator expected
I want to append the STDOUT of subprocess.call() to an existing file. My code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.