Thank you! very much Anthony. That hint saved me a lot of time - The following code worked fine.
allrecords = c.payment.all() # Fetches all the records for myrecord in allrecords['items']: webdbase.database.insert(..... Just a few words about the project. I am working with integrating a new payment gateway in web2py app and hope to publish a new slice once it is successfully completed. Thanks! again Rahul. On Friday, January 12, 2018 at 7:38:51 AM UTC+5:30, Anthony wrote: > > On Thursday, January 11, 2018 at 6:39:38 AM UTC-5, Rahul wrote: >> >> Thanks! Anthony for guiding me on this. Always #1 for helping us out. >> Now there is one last thing and it may be trivial but can you point me to >> the right direction. I used below notation. This works fine if I have a >> single record >> db.mytable.insert(field1=record['field1'], field2=record[ >> 'field2_alt_spelling'], ...) >> >> However, if I have multiple records, it fails with a type error given >> below >> TypeError: string indices must be integers >> >> *Data is in this format - * >> {u'count': 6, u'items': [{u'refund_status': None, u'tax': None, >> u'entity': u'payment', u'currency': u'INR', u'id': u'Tq99121U7', >> u'captured': False, u'fee': None, u'international': False, u'email': >> u'he...@gmail.com <javascript:>', u'status': u'failed', >> u'amount_refunded': 0, u'description': u'Purchase Description', >> u'order_id': None, u'vpa': None, u'bank': None, u'invoice_id': None, >> u'notes': [], u'card_id': u'311645', u'method': u'card', u'wallet': None, >> u'amount': 100, u'contact': u'7001394', u'error_description': u'Payment >> failed', u'error_code': u'BAD_REQUEST_ERROR', u'created_at': 15138345825}, >> {u'refund_status': ......}, >> {u'refund_status': None, .... 1513940199} , >> {u'refund_status': None, u'created_at': 1513738859}, >> > > Hard to say what the problem is without seeing your code, but your records > are a list embedded in a dictionary, so you need to extract the list and > loop over it: > > for record in data['items']: > db.mytable.insert(field1=record['field1'], ...) > > Anthony > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.