I'm writing a quick app to view a giant XML file with some AJAX style calls to viewgroup. My problem is session['groups'] not persisting. I have some old array with only 4 members that is stuck somewhere (cookie?..). That value is present when view is called. I then overwrite that session member with info from the recently opened xml file that contains 20+ members.
However, when viewgroup is called the session variable has reverted to the old value with only 4 members in the array!
Code followed by output. Note the 3 sessionStatus() calls
def sessionStatus():
print "# of groups in session = " + str(len(session['groups']))
#app.route('/')
def index():
cams = [file for file in os.listdir('xml/') if file.lower().endswith('xml')]
return render_template('index.html', cam_files=cams)
#app.route('/view/<xmlfile>')
def view(xmlfile):
path = 'xml/' + secure_filename(xmlfile)
print 'opening ' + path
xmlf = open(path, 'r')
tree = etree.parse(xmlf)
root = tree.getroot()
p = re.compile(r'Group')
groups = []
for g in root:
if (p.search(g.tag) is not None) and (g.attrib['Comment'] != 'Root'):
groups.append(Group(g.attrib['Comment']))
sessionStatus()
session['groups'] = groups
sessionStatus()
return render_template('view.html', xml=xmlfile, groups=groups)
#app.route('/viewgroup/<name>')
def viewGroup(name):
groups = session['groups']
sessionStatus()
if groups is None or len(groups) == 0:
raise Exception('invalid group name')
groups_filtered = [g for g in groups if g.name == name]
if len(groups_filtered) != 1:
raise Exception('invalid group name', groups_filtered)
group = groups_filtered[0]
prop_names = [p.name for p in group.properties]
return prop_names
Output
opening xml/d.xml
# of groups in session = 5
# of groups in session = 57
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /view/d.xml HTTP/1.1" 200 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/ivtl.css HTTP/1.1" 304 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/jquery.js HTTP/1.1" 304 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/raphael-min.js HTTP/1.1" 304 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /static/ivtl.css HTTP/1.1" 304 -
127.0.0.1 - - [17/Aug/2011 17:27:29] "GET /favicon.ico HTTP/1.1" 404 -
# of groups in session = 5
127.0.0.1 - - [17/Aug/2011 17:27:31] "GET /viewgroup/DeviceInformation HTTP/1.1" 200 -
I need all 57 groups to stay around. Any hints?
The data was simply too big to serialize into the session. Now I generate a key into a global dict and store that key in the session.
gXmlData[path] = groups
There's the problem that the global dict will stay around forever with more and more keys but the process isn't meant to live long.
Maybe your data is too big.
If your data is larger than 4KB, a server-side session is needed. Have a look at Flask-Session.
Related
I am using wagtail to build a blog website. In order to count the visits of each blog, I override the get_context() and serve() to set cookie. The codes are as follows:
def get_context(self, request):
authorname=self.author.get_fullname_or_username()
data = count_visits(request, self)
context = super().get_context(request)
context['client_ip'] = data['client_ip']
context['location'] = data['location']
context['total_hits'] = data['total_hits']
context['total_visitors'] =data['total_vistors']
context['cookie'] = data['cookie']
context['author']=authorname
return context
def serve(self, request):
context = self.get_context(request)
print(request.COOKIES)
template = self.get_template(request)
response = render(request, template, context)
response.set_cookie(context['cookie'], 'true', max_age=3000)
return response
And the function count_visits is as follows:
def count_visits(request, obj):
data={}
ct = ContentType.objects.get_for_model(obj)
key = "%s_%s_read" % (ct.model, obj.pk)
if not request.COOKIES.get(key):
blog_visit_count, created =BlogVisitNumber.objects.get_or_create(content_type=ct, object_id=obj.pk)
blog_visit_count.count += 1
blog_visit_count.save()
The problem I met is that when I reload the blog page, serve() was loaded twice. The first time request was with cookie info. But the second time the cookie of the request was {}, which caused the count of visit does not work correctly.
I do not understand why serve() is called twice everytime I reload page.
After adding a print command in serve(), the log of reload blog page is as follows:
[19/Sep/2022 23:08:44] "GET /notifications/api/unread_list/?max=5 HTTP/1.1" 200 38
{'csrftoken': 'vAnNLAp8Fb9zPkUOSrHTFGB5Bp4W4aLu8mQWPklIhX1JpDTcKIceeId03jTKJpA3', 'sessionid': '9qdgjulitvosan1twtqe0h5bpfn4z3hg', 'bloglistingpage_7_read': 'true', 'blogdetailpage_6_read': 'true'}
[19/Sep/2022 23:08:44] "GET /blog-1/ HTTP/1.1" 200 27594
{}
[19/Sep/2022 23:08:45] "GET /blog-1/ HTTP/1.1" 200 23783
[19/Sep/2022 23:08:46] "GET /notifications/api/unread_list/?max=5 HTTP/1.1" 200 38
And the log of curl is:
[19/Sep/2022 23:12:24] "GET /notifications/api/unread_list/?max=5 HTTP/1.1" 200 38
{}
[19/Sep/2022 23:12:29] "GET /blog-1/ HTTP/1.1" 200 23783
Background Information :
I have developed server in django python and deployed on AWS Elastic Beanstalk by using ELB.
Server content many API named like as /testapi, /xyz, etc.
Problem Facing :
Sometime it gave me 4xx or 200 when i called /testapi.
Attaching logs of AWS EC2 instant which show some of request are failed with 4xx response code and some are ok i.e 200.
Please guide me on the right path so I can solve it.
-----------------------Start of code-------------------
#api_view(['POST'])
#permission_classes((AllowAny,))
def get_profile_details(request):
if request.method == 'POST':
try:
logger = logging.getLogger("oauth")
logger.info("get_profile_details POST endpoint called.")
data = dict()
client_id = request.data.get(UiString.client_id)
client_secret = request.data.get(UiString.client_secret)
logger.info("get_profile_details : client_id = " + client_id)
logger.info("get_profile_details : client_secret = " + client_secret)
if helper.validateClientIdAndClientSecret(client_id, client_secret):
logger.info("get_profile_details : Invalid Client Credentials")
return helper.returnResponse(ResponseCodes.Fail, "Unauthorized access", {}, False, status.HTTP_401_UNAUTHORIZED)
try:
type = request.data.get(UiString.type)
email = request.data.get(UiString.email)
mobile = request.data.get(UiString.mobile)
username = request.data.get(UiString.username)
if helper.isNullOrEmpty(type):
return helper.returnResponse(ResponseCodes.missing_required_param, "Type should not be null", data, False,
status.HTTP_400_BAD_REQUEST)
if type == 'email' and helper.isNullOrEmpty(email):
return helper.returnResponse(ResponseCodes.missing_required_param, "Email should not be null", data, False,
status.HTTP_400_BAD_REQUEST)
elif type == 'mobile' and helper.isNullOrEmpty(mobile):
return helper.returnResponse(ResponseCodes.missing_required_param, "Mobile should not be null", data, False,
status.HTTP_400_BAD_REQUEST)
elif type == 'username' and helper.isNullOrEmpty(username):
return helper.returnResponse(ResponseCodes.missing_required_param, "Username should not be null", data,
False, status.HTTP_400_BAD_REQUEST)
try:
# Check user detail based on type
if type == 'email':
logger.info("get_profile_details : by using email as type")
user_details = User.objects.get(email=email)
user_profile_detail = user_details.user_profile
elif type == 'username':
logger.info("get_profile_details : by using username as type")
user_details = User.objects.get(username=username)
user_profile_detail = user_details.user_profile
elif type == 'mobile':
logger.info("get_profile_details : by using mobile as type")
user_profile_detail = UserProfile.objects.get(mobile1=mobile)
#user_details = User.objects.get(pk=user_profile_detail.user_id)
except (UserProfile.DoesNotExist, User.DoesNotExist) as ex:
logger.info("get_profile_details : user does not exist")
logger.exception(ex)
return helper.returnResponse(ResponseCodes.user_does_not_exist, "user does not exist",
data,
False, status.HTTP_200_OK)
except Exception as ex:
logger.info("get_profile_details : Got a exception")
logger.exception(ex)
return helper.returnResponse(ResponseCodes.exception_in_finding_user, "Got a exception",
data,
False, status.HTTP_200_OK)
user = user_profile_detail.user
user_profile_serializer = UserProfileSerializer(user.user_profile)
logger.info("get_profile_details : Got user detail : " + user.username)
data[UiString.user] = {
UiString.email : user.email,
UiString.username : user.username,
UiString.first_name : user.first_name,
UiString.last_name : user.last_name,
UiString.user_profile : user_profile_serializer.data,
}
logger.info("get_profile_details : User details retrived successfully")
return helper.returnResponse(ResponseCodes.success, "User details retrived successfully",
data,
False, status.HTTP_200_OK)
except Exception as ex:
logger.info("get_profile_details : Exception in finding user")
logger.exception(ex)
return helper.returnResponse(ResponseCodes.exception_in_finding_user, "Exception in finding user detail api",
data,
False, status.HTTP_200_OK)
except:
response = helper.generateStandardResponse(ResponseCodes.exception_in_finding_user, "Failed get user from db. Something went wrong.", data,
False);
return Response(response, status.HTTP_417_EXPECTATION_FAILED)
return Response("Method not allowed.", status.HTTP_405_METHOD_NOT_ALLOWED)
--------------------Start Of Logs -------------------
172.31.16.19 - - [28/Oct/2017:12:01:59 +0000] "POST /testapi/ HTTP/1.1" 404 218 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.2.71 - - [28/Oct/2017:12:02:01 +0000] "POST /testapi/ HTTP/1.1" 404 218 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.2.71 - - [28/Oct/2017:12:02:09 +0000] "POST /testapi/ HTTP/1.1" 404 218 "http://192.168.0.167/" "MozillaXYZ/1.0"
127.0.0.1 (-) - - [28/Oct/2017:12:02:22 +0000] "GET / HTTP/1.1" 200 54 "-" "Python-urllib/2.7"
172.31.2.71 (35.154.225.66) - - [28/Oct/2017:12:02:44 +0000] "PUT /xyz/ HTTP/1.1" 200 872 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.16.19 (35.154.225.66) - - [28/Oct/2017:12:02:54 +0000] "PUT /xyz/ HTTP/1.1" 200 834 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.2.71 (35.154.225.66) - - [28/Oct/2017:12:03:23 +0000] "POST /testapi/ HTTP/1.1" 200 866 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.16.19 (35.154.225.66) - - [28/Oct/2017:12:03:25 +0000] "PUT /xyz/ HTTP/1.1" 200 857 "http://192.168.0.167/" "MozillaXYZ/1.0"
::1 (-) - - [28/Oct/2017:12:03:33 +0000] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.25 (Amazon) mod_wsgi/3.5 Python/3.4.3 (internal dummy connection)"
::1 (-) - - [28/Oct/2017:12:03:34 +0000] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.25 (Amazon) mod_wsgi/3.5 Python/3.4.3 (internal dummy connection)"
::1 (-) - - [28/Oct/2017:12:03:44 +0000] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.25 (Amazon) mod_wsgi/3.5 Python/3.4.3 (internal dummy connection)"
::1 (-) - - [28/Oct/2017:12:03:45 +0000] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.25 (Amazon) mod_wsgi/3.5 Python/3.4.3 (internal dummy connection)"
172.31.2.71 (35.154.225.66) - - [28/Oct/2017:12:03:51 +0000] "POST /testapi/ HTTP/1.1" 200 906 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.16.19 (35.154.225.66) - - [28/Oct/2017:12:04:03 +0000] "POST /testapi/ HTTP/1.1" 200 884 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.2.71 (35.154.225.66) - - [28/Oct/2017:12:04:08 +0000] "POST /testapi/ HTTP/1.1" 200 904 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.2.71 (35.154.225.66) - - [28/Oct/2017:12:04:30 +0000] "POST /testapi/ HTTP/1.1" 200 882 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.2.71 (52.66.89.157) - - [28/Oct/2017:12:05:17 +0000] "POST /testapi/ HTTP/1.1" 200 1268 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.16.19 (35.154.225.66) - - [28/Oct/2017:12:05:33 +0000] "POST /testapi/ HTTP/1.1" 200 861 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.16.19 (35.154.225.66) - - [28/Oct/2017:12:05:48 +0000] "POST /testapi/ HTTP/1.1" 400 88 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.2.71 (35.154.225.66) - - [28/Oct/2017:12:05:53 +0000] "POST /testapi/ HTTP/1.1" 200 882 "http://192.168.0.167/" "MozillaXYZ/1.0"
172.31.2.71 (35.154.225.66) - - [28/Oct/2017:12:06:11 +0000] "PUT /xyz/ HTTP/1.1" 200 830 "http://192.168.0.167/" "MozillaXYZ/1.0"
Right now I am using Flask and a flask 3rd party library Flask-Session
Using the code below, I reload the page 4 times and get the following output:
set userid[0]
127.0.0.1 - - [27/Sep/2014 22:28:35] "GET / HTTP/1.1" 200 -
set userid[1]
127.0.0.1 - - [27/Sep/2014 22:28:37] "GET / HTTP/1.1" 200 -
set userid[2]
127.0.0.1 - - [27/Sep/2014 22:28:37] "GET / HTTP/1.1" 200 -
set userid[3]
127.0.0.1 - - [27/Sep/2014 22:28:38] "GET / HTTP/1.1" 200 -
Code:
from flask import Flask, session
from flask.ext.session import Session
app = Flask(__name__)
sess = Session()
nextId = 0
def verifySessionId():
global nextId
if not 'userId' in session:
session['userId'] = nextId
nextId += 1
sessionId = session['userId']
print ("set userid[" + str(session['userId']) + "]")
else:
print ("using already set userid[" + str(session['userId']) + "]")
sessionId = session.get('userId', None)
return sessionId
#app.route("/")
def hello():
userId = verifySessionId()
return str(userId)
if __name__ == "__main__":
app.config['SECRET_KEY'] = 'super secret key'
app.config['SESSION_TYPE'] = 'filesystem'
sess.init_app(app)
app.debug = True
app.run()
Shouldn't session['userId] be 'saved out' each time I reload the page?
You need to have cookies enabled for sessions to work. Even Flask-Session cannot track a browser without those.
Flask-Session sets a cookie with a unique id, then later on finds your session data again by that cookie.
I'm developing a site and there are some old URLs to redirect. I use something like this:
url(r'^i/personagens/*(?:index\.php)*', 'whatever.views.legacy_personanges_home', name='legacy_personanges_home'),
and in the views
def legacy_personanges_home(request):
return HttpResponsePermanentRedirect('/bio/')
While developing I collect old urls and run them on a simple verifier to check my redirects and old pages are handled accordingly. Here it is:
host = 'http://127.0.0.1:8000'
oks = 0
bads = 0
good_codes = [200,301,302]
legacy_urls = [
'/i/personagens/index.php',
'/i/personagens/',
'/i/personagens/index.php?x=1',
]
import urllib2
for path in legacy_urls:
try:
request = urllib2.Request(host + path)
request.get_method = lambda : 'HEAD'
response = urllib2.urlopen(request)
print response.getcode(), path, '-->', response.geturl()
if response.getcode() in good_codes:
oks += 1
else:
bads += 1
except urllib2.HTTPError, e:
print e.code, path
bads += 1
total = oks + bads
print 'OK: %d/%d' % (oks, total)
print 'BAD: %d/%d' % (bads, total)
Response:
200 /i/personagens/index.php --> http://127.0.0.1:8000/bio/
200 /i/personagens/ --> http://127.0.0.1:8000/bio/
200 /i/personagens/index.php?x=1 --> http://127.0.0.1:8000/bio/
OK: 3/3
BAD: 0/3
[Finished in 2.7s]
Nice! urlopen() follows redirects and the response should be a 200. geturl() shows me the final url.
Later I discovered there were lots of different new urls to redirect, so I decided to use the Django Redirects framework. I installed it and put those very 3 urls there to redirect to my '/bio/' new url.
The Weird part:
I opened http://127.0.0.1:8000/personagens/index.php in the browser, it worked, I could see the 301 there and the following 200.
I ran again the same verifier:
404 /i/personagens/index.php
404 /i/personagens/
404 /i/personagens/index.php?x=1
OK: 0/3
BAD: 3/3
[Finished in 1.2s]
I could see the logs
[28/Feb/2014 13:00:41] "HEAD /i/personagens/index.php HTTP/1.1" 404 0
[28/Feb/2014 13:00:41] "HEAD /i/personagens/ HTTP/1.1" 404 0
[28/Feb/2014 13:00:41] "HEAD /i/personagens/index.php?x=1 HTTP/1.1" 404 0
I changed the HEAD to GET just in case... still not working
thanks in advance
This is a follow up question to my previous question. I am trying to upload and display an image as an avatar following the sample app here.
This is the code I am using:
In upload.py I have:
from google.appengine.api import images
class Upload(webapp.RequestHandler):
def get(self):
self.response.out.write("""
<form action="/avatar-save" enctype="multipart/form-data" method="post">
<div><label>Avatar:</label></div>
<div><input type="file" name="img"/></div>
</form>
</body>
</html>""")
class AvatarSave(webapp.RequestHandler):
def post(self):
avatar = images.resize(self.request.get("img"), 32, 32)
greeting.avatar = db.Blob(avatar)
greeting.put()
self.redirect('/')
application = webapp.WSGIApplication(
[('/upload', Upload),
('/avatar-save', AvatarSave),
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
My first question is: How do I check that AvatarSave actually saves the image to datastore?
I try to display the image in hw.py:
class MainPage(webapp.RequestHandler):
def get(self):
siteUser = users.get_current_user()
greeting = None
if siteUser:
greeting = ("Welcome, %s! (sign out)" %
(siteUser.nickname(), users.create_logout_url("/")))
else:
greeting = ("Sign in or register" %
users.create_login_url("/"))
self.response.out.write(greeting)
query = User.all()
query.order("-userScore")
results = query.fetch(10)
self.response.out.write("""<html><head><style>
body {font-size: small;
font-family: Verdana, Helvetica, sans-serif;
}</style>
</head><body><ol>""")
for result in results:
self.response.out.write("<li>")
self.response.out.write("<b>%s</b> %s " % (result.userName, result.userLatestComment))
self.response.out.write("<div><img src='img?img_id=%s'></img>" % result.key())
self.response.out.write("</li>")
self.response.out.write("</ol></body></html>")
class Image (webapp.RequestHandler):
def get(self):
greeting = db.get(self.request.get("img_id"))
if greeting.avatar:
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(greeting.avatar)
else:
self.response.out.write("No image")
application = webapp.WSGIApplication(
[('/', MainPage),
('/img', Image),
],
debug=True)
But all I get is the broken image link icon for each line displayed. (I have 8 lines displayed.)
In the Logs I see this:
INFO 2010-12-04 01:03:57,641 dev_appserver.py:3283] "GET / HTTP/1.1" 200 -
INFO 2010-12-04 01:03:57,703 dev_appserver.py:3283] "GET /img?img_id=ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGBMM HTTP/1.1" 200 -
INFO 2010-12-04 01:03:57,756 dev_appserver.py:3283] "GET /img?img_id=ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGBUM HTTP/1.1" 200 -
INFO 2010-12-04 01:03:58,734 dev_appserver.py:3283] "GET /img?img_id=ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGBIM HTTP/1.1" 200 -
INFO 2010-12-04 01:03:58,812 dev_appserver.py:3283] "GET /img?img_id=ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGFkM HTTP/1.1" 200 -
INFO 2010-12-04 01:03:58,878 dev_appserver.py:3283] "GET /img?img_id=ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGFsM HTTP/1.1" 200 -
INFO 2010-12-04 01:03:58,934 dev_appserver.py:3283] "GET /img?img_id=ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGFoM HTTP/1.1" 200 -
INFO 2010-12-04 01:03:58,986 dev_appserver.py:3283] "GET /img?img_id=ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGGkM HTTP/1.1" 200 -
INFO 2010-12-04 01:03:59,040 dev_appserver.py:3283] "GET /img?img_id=ag1oZWxsby0xLXdvcmxkcgoLEgRVc2VyGGwM HTTP/1.1" 200 -
INFO 2010-12-04 01:04:00,102 dev_appserver.py:3283] "GET /favicon.ico HTTP/1.1" 200 -
As far as I understand, some images are fetched from the datastore; but I uploaded only 1 image (or I thought I did) but according to the logs the id for each image is different.
Can anyone help me understand what is going on here; and how to fix it? Many thanks for your help.
Update
In response to Ben's answer I updated the code like this:
This is the model I am using:
class User(db.Model):
userEmail = db.StringProperty()
....
avatar = db.BlobProperty()
and this is new AvatarSave:
class AvatarSave(webapp.RequestHandler):
def post(self):
q = User.all()
q.filter("userEmail =", "az#example.com")
qTable = q.fetch(1)
if qTable:
for row in qTable:
avatar = images.resize(self.request.get("img"), 32, 32)
row.avatar = db.Blob(avatar)
db.put(qTable)
else:
self.response.out.write("user not found")
self.redirect('/')
I believe this now updates the avatar of the user associated with the userEmail "az#example.com". Is this correct?
I updated hw.py to display only this user as well:
query = User.all()
query.filter("userEmail =", "az#example.com")
results = query.fetch(1)
self.response.out.write("""<html><head><style>
body {font-size: small;
font-family: Verdana, Helvetica, sans-serif;
}</style>
</head><body><ol>""")
for result in results:
self.response.out.write("<li>")
self.response.out.write("<b>%s</b> %s " % (result.userName, result.userLatestComment))
self.response.out.write("<div><img src='img?img_id=%s'></img>" % result.key())
self.response.out.write("</li>")
self.response.out.write("</ol></body></html>")
But there is still a problem because instead of displaying the image, I get "None" and the image link is broken.
Furthermore, when I look at the Datastore Viewer, I don't see the "avatar" column. But I see that some blob was updated at some point:
Entity Kind: __BlobUploadSession__
Key: ag10ZWxs....
ID: 125
Key Name:
creation: 1291388993.27
state: init
success_path: /upload
Not sure what is going on here and how to fix it. Any suggestion will be welcome.
In the log, you're seeing different image IDs because you're requesting up to 10 user objects from the Datastore, and the Datastore query is looking for the users regardless of whether or not they have an image stored (maybe you made 8 User objects in the course of testing).
As to why the avatars aren't saving:
class AvatarSave(webapp.RequestHandler):
def post(self):
avatar = images.resize(self.request.get("img"), 32, 32)
greeting.avatar = db.Blob(avatar)
Unless some code is missing from your example, the "greeting" variable is not set here. You have to first create a new greeting (by making a new instance of whatever model it uses) or load the appropriate one, then set the avatar to it, then greeting.put()
Update
If your code is indented like:
qTable = q.fetch(1)
if qTable:
for row in qTable:
avatar = images.resize(self.request.get("img"), 32, 32)
row.avatar = db.Blob(avatar)
db.put(qTable)
It will not work. What you want is probably:
qTable = q.fetch(1)
if qTable:
for row in qTable:
avatar = images.resize(self.request.get("img"), 32, 32)
row.avatar = db.Blob(avatar)
db.put(qTable)
But since you're working with only one object here, it would be simpler to replace your current use of fetch(1) and instead do:
currentUser = q.get()
if currentUser is not None:
avatar = images.resize(self.request.get("img"), 32, 32)
currentUser.avatar = db.Blob(avatar)
currentUser.put()