I'm looping all the rows and I want to return it but even after looping all the rows and even data is saving in the database but its not getting exit from it due to which I'm getting an error as 'str' object has no attribute 'get'
. I don't know where I'm going wrong
This what I tried
Views.py:
@api_view(['POST'])
def SaveUserResponse(request):
if request.method == 'POST':
cursor = connection.cursor()
if request.data:
for ran in request.data:
auditorid =ran.get('AuditorId')
print('SaveUserResponse auditorid---', auditorid)
ticketid = ran.get('TicketId')
Agents = ran.get('Agents')
Comments = ran.get('Comments')
Supervisor = ran.get('Supervisor')
sid = 0
print('sid--', sid)
qid = ran.get('QId')
print('qid---', qid)
answer = ran.get('Answer')
cursor.execute('EXEC [dbo].[sp_SaveAuditResponse] @auditorid=%s,@ticketid=%s,@qid=%s,@answer=%s,@sid=%s',
(auditorid,ticketid,qid,answer, sid))
result_st = cursor.fetchall()
print('sp_SaveAuditResponse', result_st)
for row in result_st:
print('sp_SaveAuditResponse', row)
return Response(row[0])
print('after after')
return Response(0)
Here, is the payload:
[{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":42,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":43,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":44,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":45,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":46,"Answer":"3","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":47,"Answer":"5","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":48,"Answer":"5","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":49,"Answer":"2","SID":"0","Comments":""},
{"AuditorId":130,"Agents":"","Supervisor":"","TicketId":"325423432","QId":50,"Answer":"5","SID":"0","Comments":""}]
One of your request.data is not a dict but a string, to know where this wrong value appear, try something like :
if request.data:
for index, ran in enumerate(request.data):
if isInstance(if isinstance(element, dict)):
// retrieve data
else:
print(str(index), ran)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.