KeyError this says that key(partner) is not in dict ?

Posted by Ansh Jain on Stack Overflow See other posts from Stack Overflow or by Ansh Jain
Published on 2010-05-25T09:12:45Z Indexed on 2010/05/25 9:21 UTC
Read the original article Hit count: 249

Filed under:
|
|

I am trying to make an chat application using python and django. I almost complete it and its working fine for 8-10 minutes when two persons are chatting after that certain time it shows an error.

here is the traceback : -

Traceback (most recent call last):

  File "\Django_chat\django_chat\chat\views.py", line 55, in receive

    message = chatSession.getMessage(request.session['partner'],request.session['uid'],afterTime)

  File "C:\Python26\lib\site-packages\django\contrib\sessions\backends\base.py", line 47, in __getitem__

    return self._session[key]

KeyError: 'partner'

here is the receive module :-

def receive(request):

    message received by this user
    chatSession = chat()
data = request.POST
afterTime = data['lastMsgTime']
try:
            message = chatSession.getMessage(request.session['partner'],request.session['uid'],afterTime)
    except:
            #partnerId = virtual_users.objects.get(id=request.session['uid']).partner
            print('there is an error in receive request')
            traceback.print_exc(file=open("/myapp.log","a"))

    msg = serializers.serialize("json", message)
    return HttpResponse(msg)

Please Help me :( thanks Ansh J

© Stack Overflow or respective owner

Related posts about python

Related posts about django