david
david

Reputation: 161

How to use cursor with google app engine?

I got this error:cursor argument should be str or unicode (0) when running this python code :

#get cursor
        curs = self.request.get('cursor',0)
        cursor = Cursor(urlsafe=curs)
        #get messages
        messages, next_curs, more = Message().queryMessages(userId=945454,bussId=454545,cursor=cursor)

the error pointing to cursor = Cursor(urlsafe=curs)

what's the problem ?

Upvotes: 0

Views: 145

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599490

You've set a default for cursor of 0. So, if it's not in the request, that is the value that will be used as the argument to instantiate a new cursor. Obviously, that's not a valid value.

Instead, don't set a default, and only instantiate a cursor if you get a value in the request:

cursor = None
curs = self.request.get('cursor')
if curs:
    cursor = Cursor(urlsafe=curs)

Upvotes: 1

Related Questions