KeyError this says that key(partner) is not in dict ?
- by Ansh Jain
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