I'm getting the following error after a post:
'dict' object has no attribute 'status_code'
I'm using django 3.1.7 and python 3.8.
Can anyone help me with this problem? I'm new to this stuff and can't seem to solve it alone.
the .py:
from gluon import *
from .models import *
from lxml import etree as ET
import re
import requests
def update_customer(request, p_externalcode, p_addressexternalcode, p_street, p_nr, p_addition, p_zipcode, p_city, p_country, p_complexnr, p_region, p_company_code, controle, omgeving):
url = request.session['omgeving_url']+'/mds/soapservice/outbound.asmx'
lic = '{'+request.session['omgeving_lic']+'}'
gebruiker = request.session['omgeving_geb']
wachtwoord = request.session['omgeving_pas']
omgnaam = request.session['omgeving_naam']
headers = {'content-type':'text/xml', 'charset':'utf-8'}
# opbouw van de SOAP-xml
SOAP_NS = 'http://schemas.xmlsoap.org/soap/envelope/'
PCA_NS = 'http://www.pcamobile.com/mds'
ns_map = {'SOAP': SOAP_NS}
pca_map = {None: PCA_NS}
envelope = ET.Element(ET.QName(SOAP_NS, 'Envelope'), nsmap=ns_map)
body = ET.SubElement(envelope, ET.QName(SOAP_NS, 'Body'), nsmap=ns_map)
rqoutboundmessage = ET.SubElement(body, ET.QName(PCA_NS,'RqOutboundMessage'), nsmap=pca_map)
header = ET.SubElement(rqoutboundmessage, 'Header')
version = ET.SubElement(header, 'Version')
companyid = ET.SubElement(header,'CompanyID')
messageid = ET.SubElement(header,'MessageID')
messagetype = ET.SubElement(header,'MessageType')
testmessage = ET.SubElement(header,'TestMessage')
rqdefinition = ET.SubElement(rqoutboundmessage,'RqCustomerDefinition')
nodes = ET.SubElement(rqdefinition,'Customers')
updated = ET.SubElement(nodes,'Updated')
node = ET.SubElement(updated,'Customer')
externalcode = ET.SubElement(node,'ExternalCode')
if str(p_addressexternalcode or '') != '':
if p_addressexternalcode[:10] == 'AholdStore':
name = ET.SubElement(node,'Name')
name.text = p_addressexternalcode[-4:]
address = ET.SubElement(node,'Address')
if str(p_addressexternalcode or '') != '':
addrexternalcode = ET.SubElement(address,'ExternalCode')
addrexternalcode.text = re.sub('[^ \-\.0-9#A-Z_a-z]+', '', p_addressexternalcode)
street = ET.SubElement(address,'Street')
nr = ET.SubElement(address,'Nr')
if str(p_addition or '') != '':
nraddition = ET.SubElement(address,'NrAddition')
nraddition.text = p_addition
zipcode = ET.SubElement(address,'ZipCode')
city = ET.SubElement(address,'City')
country = ET.SubElement(address,'Country')
countrycode = ET.SubElement(country,'ExternalCode')
if str(p_complexnr or '') != '':
complexname = ET.SubElement(address,'ComplexName')
complexname.text = p_complexnr
region = ET.SubElement(node,'Region')
regexternalcode = ET.SubElement(region,'ExternalCode')
companycode = ET.SubElement(node,'CompanyID')
#vulling van de SOAP-xml
companyid.text = lic
version.text = '1.0'
messageid.text = '{00009000-0000-0000-0000-000000000000}'
messagetype.text = 'RqCustomerDefinition'
testmessage.text = str(controle)
externalcode.text = re.sub('[^.0-9#A-Z_a-z]+', '', p_externalcode)
street.text = p_street
nr.text = str(p_nr)
zipcode.text = p_zipcode
city.text = p_city
countrycode.text = p_country
regexternalcode.text= p_region
companycode.text = p_company_code
# maak er een tekstfile van.
body = ET.tostring(envelope, pretty_print=True)
response = requests.post(url,data=body,headers=headers, auth=(gebruiker, wachtwoord))
root = ET.fromstring(response.text.encode('ascii','ignore'))
if response.status_code == 200:
status = 0
else:
status = 1
Verwerking.objects.create(omgeving=omgnaam, Status=status, bericht=body, antwoord=ET.tostring(root, pretty_print=True).decode())
return status
Terminal Response:
[21/Mar/2021 16:25:49] "GET /woningbeheer HTTP/1.1" 200 58463
[21/Mar/2021 16:25:50] "GET /static/js/main.js HTTP/1.1" 304 0
[21/Mar/2021 16:25:50] "GET /woningbeheer HTTP/1.1" 200 58468
Internal Server Error: /woningbeheer/syncPCAind/5897
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Python38\lib\site-packages\django\utils\deprecation.py", line 116, in __call__
response = self.process_response(request, response)
File "C:\Python38\lib\site-packages\django\middleware\common.py", line 106, in process_response
if response.status_code == 404:
AttributeError: 'dict' object has no attribute 'status_code'
[21/Mar/2021 16:25:53] "GET /woningbeheer/syncPCAind/5897 HTTP/1.1" 500 65689
Internal Server Error: /woningbeheer/syncPCAind/9640
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Python38\lib\site-packages\django\utils\deprecation.py", line 116, in __call__
response = self.process_response(request, response)
File "C:\Python38\lib\site-packages\django\middleware\common.py", line 106, in process_response
if response.status_code == 404:
AttributeError: 'dict' object has no attribute 'status_code'
[21/Mar/2021 16:39:41] "GET /woningbeheer/syncPCAind/9640 HTTP/1.1" 500 65689
Maybe useful:
AttributeError at /woningbeheer/syncPCAind/82689
'dict' object has no attribute 'status_code'
Request Method: GET
Request URL: http://127.0.0.1:8000/woningbeheer/syncPCAind/82689
Django Version: 3.1.7
Exception Type: AttributeError
Exception Value:
'dict' object has no attribute 'status_code'
Exception Location: C:\Python38\lib\site-packages\django\middleware\common.py, line 106, in process_response
Python Executable: C:\Python38\python.exe
Python Version: 3.8.8
Python Path:
['C:\\Users\\wgeboers\\OneDrive - Coen Hagedoorn Bouwgroep '
'B.V\\Django-Docker\\databeheer',
'C:\\Python38\\python38.zip',
'C:\\Python38\\DLLs',
'C:\\Python38\\lib',
'C:\\Python38',
'C:\\Python38\\lib\\site-packages']
Server time: Sun, 21 Mar 2021 15:44:25 +0000
Thanks in advance and if there is more information needed let me know.
Related
I keep getting the following error message whenever I run my code:
Attempting to parse Socialblade: https://socialblade.com/youtube/user/aantonop
Got no_of_videos: 325
Internal Server Error: /api/connect_youtube/
Traceback (most recent call last):
File "/Users/test/projects/my-api/api/views.py", line 160, in post
response.update(scraper.collect_creator_data(request.data['youtubeChannelUsername']))
File "/Users/test/projects/my-api/api/scraper.py", line 23, in collect_creator_data
process_socialblade(username)
File "/Users/test/projects/my-api/api/scraper.py", line 68, in process_socialblade
if no_of_subscribers:
UnboundLocalError: local variable 'no_of_subscribers' referenced before assignment
I suspect its due to the use of global variables in my script but not sure how to rectify it. I have set up the global variables to be processed by multiple methods.
How do I fix it? Code below:
from bs4 import BeautifulSoup
from test.settings.base import YOUTUBE_URL, YOUTUBE_API_KEY
from urllib.request import Request, urlopen
import ssl
no_of_videos = 0
no_of_subscribers = 0
no_of_views = 0
avg_views = 0
like_count = 0
dislike_count = 0
channel_id = None
photo = None
description = None
start_date = None
title = None
keywords = None
sb_grade = None
def collect_creator_data(username):
process_socialblade(username)
process_youtube(username)
return {"id": channel_id,
"photo": photo,
"title": title,
"like_count": like_count,
"dislike_count": dislike_count,
"keywords": keywords,
"description": description,
"start_date": start_date,
"no_of_videos": no_of_videos,
"no_of_subscribers": no_of_subscribers,
"no_of_views": no_of_views,
"avg_views": avg_views,
"sb_grade": sb_grade
}
def process_socialblade(username):
socialblade_user_url = 'https://socialblade.com/youtube/user/' + username
context = ssl._create_unverified_context()
print('Attempting to parse Socialblade:', socialblade_user_url)
q = Request(socialblade_user_url)
q.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) '
'Chrome/23.0.1271.64 Safari/537.11')
q.add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
q.add_header('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')
q.add_header('Accept-Encoding', 'none')
q.add_header('Accept-Language', 'en-US,en;q=0.8')
q.add_header('Connection', 'keep-alive')
socialblade_user_html = urlopen(q, context=context).read()
if socialblade_user_html:
soup = BeautifulSoup(socialblade_user_html, "html.parser")
youtube_user_top_info_list = soup.findAll('div', attrs={'class': 'YouTubeUserTopInfo'})
for i in youtube_user_top_info_list:
try:
no_of_videos = i.find('span', id='youtube-stats-header-uploads').get_text()
except AttributeError:
pass
if no_of_videos:
print('Got no_of_videos:', no_of_videos)
try:
no_of_subscribers = i.find('span', id='youtube-stats-header-subs').get_text()
except AttributeError:
pass
if no_of_subscribers:
print('Got no_of_subscribers:', no_of_subscribers)
try:
no_of_views = i.find('span', id='youtube-stats-header-views').get_text()
except AttributeError:
pass
if no_of_views:
print('Got no_of_views:', no_of_views)
else:
print('Could not parse Socialblade:', socialblade_user_html)
Should I create global variables in process_socialblade?
I get this error and I don't know what the problem is.
Code:
__author__ = 'victor'
import requests
import xmltodict
url = 'http://webservices.ns.nl/ns-api-storingen?station=UT'
user = 'victor_shao#hotmail.com'
passw = 'dMHAg67WACsUdrQmqctr3giaTpTnsJmhPP2EcQWlVnMw3zmHXvSE-A'
response = requests.get(url, auth=(user, passw))
xmldi = xmltodict.parse(response.text)
storing = 0
allestoringen = 4
print("Storingen",'\n','ongeplande storingen')
print('{0:15s}'.format('id'),'{0:40s}'.format('traject'),'{0:20s}'.format('reden'),'{0:100s}'.format('bericht'),'{0:25s}'.format('datum'))
for storing in range(0, allestoringen):
id = xmldi['Storingen']['Ongepland']['Storing']['id']
traject = xmldi['Storingen']['Ongepland']['Storing']['Traject']
reden = xmldi['Storingen']['Ongepland']['Storing']['Reden']
bericht = xmldi['Storingen']['Ongepland']['Storing']['Bericht']
datum = xmldi['Storingen']['Ongepland']["Storing"]['Datum']
print("Geplande storingen ")
print('{0:25s)'.format('id'),'{0:40s}'.format('traject'),'{0:35s}'.format('periode'),'{0:200s}'.format('advies'),'{0:250s}'.format('bericht'),'{0:50s}'.format('oorzaak'),'{0:30s}'.format('vertraging'))
for storing in range(0, allestoringen):
id = xmldi['Storingen']['Gepland']['Storing']['id']
traject = xmldi['Storingen']['Gepland']['Storing']['Traject']
periode = xmldi['Storingen']['Gepland']['Storing']['Periode']
advies = xmldi['Storingen']['Gepland']['Storing']['Advies']
bericht = xmldi['Storingen']['Gepland']['Storing']['Bericht']
oorzaak = xmldi['Storingen']['Gepland']['Storing']['Oorzaak']
vertraging = xmldi['Storingen']['Gepland']['Storing']['Vertraging']
Here is the output, where I should fill in the information:
C:\Python34\python.exe C:/Users/avi/PycharmProjects/untitled1/storing.py Storingen
ongeplande storingen id traject
reden bericht
datum Traceback (most recent call last): File
"C:/Users/avi/PycharmProjects/untitled1/storing.py", line 18, in
id = xmldi['Storingen']['Ongepland']['Storing']['id'] TypeError: 'NoneType' object is not subscriptable
Process finished with exit code 1
How can I fix this? I would appreciate any help.
Since xmldi['Storingen']['Ongepland'] has the value None
id = xmldi['Storingen']['Ongepland']['Storing']['id']
should be changed to:
id = xmldi['Storingen']['Gepland']['Storing']['id']
i have a deployment on appengine, im getting this error when i'm tryng to assign a trip
def get(self):
from trips.end_trip import notify_cancelation
"""
GET /2/drivers/report_trip_arrival
> trip_id /custom_id
> device_id
> driver_id
> event_timestamp
< 200 application/json
Changes the trip status to 4, your taxi has arrived
"""
responseJSON = {}
self.response.headers['Content-Type'] = "application/json"
trip_id = self.request.get("trip_id")
custom_trip_id = self.request.get("custom_id")
device_id = self.request.get("device_id")
logging.info("Report arrival")
logging.info(str(trip_id))
logging.info(str(custom_trip_id))
logging.info(str(device_id))
#Get the trip
# fixing
try:
trip = trip_finder.find_trip(trip_id=trip_id, custom_id=custom_trip_id)
except:
trip = None
responseJSON["Status"] = "OK"
return
driver_id = self.request.get('driver_id')
if driver_id:
driver_id = int(driver_id)
if trip.selected_driver.get().id() != driver_id:
responseJSON = {'status': 'OK', 'Staus': 'OK'}
json.dump(responseJSON, self.response.out)
return
if trip:
#deferred.defer(notify_arrival, trip.key.id(), _queue="delivery")
params = {}
params["trip_id"] = trip.key.id()
taskqueue.add(url="/2/delivery/task/notify_arrival", params=params, queue_name="delivery")
last_status = trip.last_status()
#If we are already on status 4, we just return OK
if last_status.id != "4":
#Update the status
#ripStatus(trip=trip.key, id="4", message=trip_statuses["4"], timestamp=now()).put()
trip.change_status("4")
#Alert the passenger
name = trip.traveler_name.split()[0] if trip.traveler_name else ""
message_status = name + ", ha llegado tu taxi :)"
responseJSON["Status"] = "OK"
responseJSON["status"] = "OK"
# if the trip was canceled notify the driver
if last_status.id == "16":
#deferred.defer(notify_cancelation, trip.key.id(), _queue="endtrip")
params = {'trip_id': trip.key.id()}
taskqueue.add(url="/2/trips/task/notify_cancelation", params=params, queue_name="endtrip")
#deferred.defer(notify_cancelation, trip.key.id(), _queue="endtrip")
else:
responseJSON["Status"] = "OK"
responseJSON["status"] = "OK"
self.response.out.write(json.dumps(responseJSON))
This is the full details:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/base/data/home/apps/s~precise-line-762/v-4-4-03.383164018327881359/security/security.py", line 47, in wrapper
return handler(request)
File "/base/data/home/apps/s~precise-line-762/v-4-4-03.383164018327881359/drivers/handlers.py", line 141, in get
if trip.selected_driver.get().id() != driver_id:
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/ndb/model.py", line 3640, in __getattr__
return super(Expando, self).__getattribute__(name)
AttributeError: 'Driver' object has no attribute 'id'
You have to pick object's ID from key property.
Looks like your trip.selected_driver is a Key already. If you want to ensure the object exist then call trip.selected_driver.get().key.id()
From my view, I am simply returning
context = {'message':'Request Accepted'}
return HttpResponse(context)
I am calling this view with AJAX call and its returning Http 500
with error message
KeyError at /routes/AcceptRequest/
'status'
Request Method: POST
when i try to stringify the response in javascript it gives :
{"readyState":4,"responseText":"KeyError at /routes/AcceptRequest/\n'status'\n\nRequest Method: POST\nRequest URL: http://localhost:8000/routes/AcceptRequest/\nDjango Version: 1.4\nPython Executable: /home/subodh/joinwheelsv6/env/bin/python\nPython Version: 2.7.3\nPython Path: ['/home/subodh/joinwheelsv6/env/joinwheels', '/home/subodh/joinwheelsv6/env/lib/python2.7/site-packages/PIL-1.1.7-py2.7-linux-x86_64.egg', '/home/subodh/joinwheelsv6/env/lib/python2.7', '/home/subodh/joinwheelsv6/env/lib/python2.7/plat-linux2', '/home/subodh/joinwheelsv6/env/lib/python2.7/lib-tk', '/home/subodh/joinwheelsv6/env/lib/python2.7/lib-old', '/home/subodh/joinwheelsv6/env/lib/python2.7/lib-dynload', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/home/subodh/joinwheelsv6/env/local/lib/python2.7/site-packages', '/home/subodh/joinwheelsv6/env/lib/python2.7/site-packages']\nServer time: Thu, 17 Oct 2013 15:48:36 +0530\nInstalled Applications:\n('django.contrib.auth',\n 'django.contrib.contenttypes',\n 'django.contrib.sessions',\n 'django.contrib.sites',\n 'django.contrib.messages',\n 'django.contrib.staticfiles',\n 'django.contrib.admin',\n 'django.contrib.admindocs',\n 'south',\n 'account',\n 'socialaccounts',\n 'routes',\n 'Groups')\nInstalled Middleware:\n('django.middleware.common.CommonMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware')\n\nTraceback:\nFile \"/home/subodh/joinwheelsv6/env/local/lib/python2.7/site-packages/django/core/handlers/base.py\" in get_response\n 111. response = callback(request, *callback_args, **callback_kwargs)\nFile \"/home/subodh/joinwheelsv6/env/local/lib/python2.7/site-packages/django/views/generic/base.py\" in view\n 48. return self.dispatch(request, *args, **kwargs)\nFile \"/home/subodh/joinwheelsv6/env/local/lib/python2.7/site-packages/django/views/generic/base.py\" in dispatch\n 69. return handler(request, *args, **kwargs)\nFile \"/home/subodh/joinwheelsv6/env/joinwheels/routes/views.py\" in post\n 1157. return HttpResponse(response['Status'])\nFile \"/home/subodh/joinwheelsv6/env/local/lib/python2.7/site-packages/django/http/__init__.py\" in __getitem__\n 615. return self._headers[header.lower()][1]\n\nException Type: KeyError at /routes/AcceptRequest/\nException Value: 'status'\nRequest information:\nGET: No GET data\n\nPOST:\ncsrfmiddlewaretoken = u'Dxm5R7omqawuGtJ2v8AuOGsDXXdTCXCa'\nRequestID = u'7'\n\nFILES: No FILES data\n\nCOOKIES:\ncsrftoken = 'Dxm5R7omqawuGtJ2v8AuOGsDXXdTCXCa'\nsessionid = '139167c44021568cf40311753e0480fc'\n\nMETA:\nwsgi.version = \nwsgi.multiprocess = False\nRUN_MAIN = 'true'\nHTTP_REFERER = 'http://localhost:8000/account/TravelCard/Ride/2059/7/'\nGNOME_DESKTOP_SESSION_ID = 'this-is-deprecated'\nSERVER_PROTOCOL = 'HTTP/1.1'\nSERVER_SOFTWARE = 'WSGIServer/0.1 Python/2.7.3'\nSCRIPT_NAME = u''\nLESSOPEN = '| /usr/bin/lesspipe %s'\nREQUEST_METHOD = 'POST'\nLOGNAME = 'subodh'\nUSER = 'subodh'\nHTTP_ORIGIN = 'http://localhost:8000'\nPATH = '/home/subodh/joinwheelsv6/env/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games'\nQUERY_STRING = ''\nGNOME_KEYRING_CONTROL = '/tmp/keyring-KIXbNa'\nPS1 = '(env)\\\\[\\\\e]0;\\\\u#\\\\h: \\\\w\\\\a\\\\]${debian_chroot:+($debian_chroot)}\\\\u#\\\\h:\\\\w\\\\$ '\nDISPLAY = ':0'\nSSH_AGENT_PID = '2016'\nLANG = 'en_IN'\nTERM = 'xterm'\nSHELL = '/bin/bash'\nXDG_SESSION_PATH = '/org/freedesktop/DisplayManager/Session0'\nXAUTHORITY = '/home/subodh/.Xauthority'\nLANGUAGE = 'en_IN:en'\nSESSION_MANAGER = 'local/dell:#/tmp/.ICE-unix/1981,unix/dell:/tmp/.ICE-unix/1981'\nSHLVL = '1'\nMANDATORY_PATH = '/usr/share/gconf/ubuntu.mandatory.path'\nwsgi.url_scheme = 'http'\nCOMPIZ_CONFIG_PROFILE = ...
Well, you seem to be doing something else that you haven't explained. From your error, cleaned up slightly:
File "/home/subodh/joinwheelsv6/env/joinwheels/routes/views.py" in post
1157. return HttpResponse(response['Status'])
So you have some code in views.py that is looking for a Status field that doesn't exist. Of course, we have no idea why.
Change the return line:
import json
return HttpResponse(json.dumps(context))
I get a problem in a form handler in app engine (Python). Basically when I post the form to the handler I get the following traceback:
INFO 2011-02-07 14:06:59,364 dev_appserver.py:3317] "GET /favicon.ico HTTP/1.1" 404 -
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/wsgiref/handlers.py", line 92, in run
self.result = application(self.environ, self.start_response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 531, in __call__
handler.handle_exception(e, self.__debug)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/webapp/__init__.py", line 394, in handle_exception
self.error(500)
TypeError: 'bool' object is not callable
INFO 2011-02-07 14:07:01,986 dev_appserver.py:3317] "POST /newevent HTTP/1.1" 500 -`
On the browser I get the message 'A server error occurred. Please contact the administrator'. As you can see, the error happens before the POST command, and doesn't seem to stem from any of my handler code. Here's the handler class for that form (post_secure is a method called by the post method in the parent class):
class SaveEvent(BaseHandler):
def post_secure(self):
userinfo = db.GqlQuery("SELECT * FROM User WHERE fbid = :1", self.user['uid'])[0]
newevent = Event(parent=userinfo)
self.error = False
self.template_values = {}
if (self.request.get('eventname') == ""):
self.template_values['eventnameerror'] = True
self.error = True
else:
newevent.eventname = self.request.get('eventname')
if (self.request.get('venuename') == ""):
self.template_values['venuenameerror'] = True
self.error = True
else:
newevent.venuename = self.request.get('venuename')
if (re.match("[0-9]+\.[0-9][0-9]", self.request.get('eventprice')) == None):
self.template_values['eventpriceerror'] = True
self.error = True
else:
newevent.price_pence = int(float(self.request.get('eventprice')) * 100)
if (re.match("[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]", self.request.get('eventdate')) == None):
self.template_values['eventdateerror'] = True
self.error = True
else:
day = re.split("/", self.request.get('eventdate'))[0]
month = re.split("/", self.request.get('eventdate'))[1]
year = re.split("/", self.request.get('eventdate'))[2]
if (re.match("[0-2][0-9]:[0-5][0-9]", self.request.get('eventtime')) == None):
self.template_values['eventtimeerror'] = True
self.error = True
else:
hours = re.split(":", self.request.get('eventtime'))[0]
minutes = re.split(":", self.request.get('eventtime'))[1]
try:
newevent.date = datetime.datetime(year, month, day, hours, minutes, 0, 0)
except ValueError:
self.template_values['eventdatetimeerror'] = True
self.error = True
if (newevent.date < datetime.datetime.now()):
self.template_values['eventdateerror2'] = True
self.error = True
if (self.request.get('eventlink') == ""):
self.template_values['eventlinkerror'] = True
self.error = True
if (self.error == True):
self.template_values['eventname'] = self.request.get('eventname')
self.template_values['venuename'] = self.request.get('venuename')
self.template_values['eventprice'] = self.request.get('eventprice')
self.template_values['eventdate'] = self.request.get('eventdate')
self.template_values['eventtime'] = self.request.get('eventtime')
self.template_values['eventlink'] = self.request.get('eventlink')
self.tpl('addevent.html', self.template_values)
newevent.put()
self.template_values = {
'newevent' : newevent
}
self.tpl('eventadded.html', self.template_values)
The RequestHandler class has a method named error
error(code)
A shortcut method for handlers to use to return an error response. Clears the response output stream and sets the HTTP error code to code. Equivalent to calling self.response.clear() and self.response.set_status(code).
Your POST handler above overwrites that method with a boolean value, and then when the framework attempts to call self.error(500) it throws an exception because the value of self.error is no longer a callable.
Use a different member variable name than error to prevent this.