Odoo Help


How to resolve "TypeError: list indices must be integers, not str" ?

Anirudh Lou
on 10/14/14, 11:25 PM 28,544 views

Hi, anyone can help me resolve this problem? Here is my code:

data['form'] = self.read(cr,uid,ids,['alphalist_category_type','a_alpha_type','fiscalyear_id'])
year1 = data['form']['fiscalyear_id']
date_code = re.split('-',contract.date_start)
year2 = int(date_code[0])
if data['form']['a_alpha_type'] == 'prev' and year2 < int(year1):

and upon running i get this error message:
"year1 = data['form']['fiscalyear_id']
TypeError: list indices must be integers, not str"

i tried to cast fiscalyear_id as int, but i get this error message:
"year1 = data['form'][int('fiscalyear_id')]
ValueError: invalid literal for int() with base 10: 'fiscalyear_id' "

Help, please!


Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 10/15/14, 12:43 AM


data['form'] = self.read(cr,uid,ids,['alphalist_category_type','a_alpha_type','fiscalyear_id']

Above line tells that data['form'] having list of the records which are return by the read method. So, the data is looks like below.

data['form'] is like : [{'id':1,'alphalist_category_type':'xx', . . .}, {'id':2,'alphalist_category_type':'xx', . . .}, {'id':3,'alphalist_category_type':'xx', . . .}]

So, when you have access it like : year1 = data['form']['fiscalyear_id'] 

In the above statement of course we are receiving an error as you have "TypeError: list indices must be integers, not str".

You can do two things.

1) Using loop you can access like below :

for data_form in data['form']:

    # your code in that you can get data 

    year1 = data_form['fiscalyear_id']  # If 'fiscalyear_id' is many2one field then you will get the data like (Id, name). To get the Id you have to wirte down data_form['fiscalyear_id'][0] and for its name data_form['fiscalyear_id'][1].


2) You can get the data like :

year1 = data['form'][0]['fiscalyear_id']  #It will give you the data of first record.

I hope you will get this answer and it is helpful to you.

Oh my, thank you very much sir. It really helps me. Thank you, thank you very much.

Anirudh Lou
on 10/15/14, 2:04 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 10/14/14, 11:25 PM
Seen: 28544 times
Last updated: 3/16/15, 8:10 AM