BittyTax icon indicating copy to clipboard operation
BittyTax copied to clipboard

Method getiterator has been removed in Python versions >=3.9

Open achilleasatha opened this issue 3 years ago • 2 comments

Using bittytax_conv on *.xlsx files raises an error as a deprecated method is being used. See here for a suggested workaround.

bittytax_conv deposit_history\ 11.39.28.xlsx Traceback (most recent call last): File "/usr/local/bin/bittytax_conv", line 8, in <module> sys.exit(main()) File "/usr/local/lib/python3.9/site-packages/bittytax/conv/bittytax_conv.py", line 101, in main do_read_file(pathname, args) File "/usr/local/lib/python3.9/site-packages/bittytax/conv/bittytax_conv.py", line 140, in do_read_file for worksheet, datemode in DataFile.read_excel(pathname): File "/usr/local/lib/python3.9/site-packages/bittytax/conv/datafile.py", line 64, in read_excel with xlrd.open_workbook(filename) as workbook: File "/usr/local/lib/python3.9/site-packages/xlrd/__init__.py", line 130, in open_workbook bk = xlsx.open_workbook_2007_xml( File "/usr/local/lib/python3.9/site-packages/xlrd/xlsx.py", line 812, in open_workbook_2007_xml x12book.process_stream(zflo, 'Workbook') File "/usr/local/lib/python3.9/site-packages/xlrd/xlsx.py", line 266, in process_stream for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator(): AttributeError: 'ElementTree' object has no attribute 'getiterator'

achilleasatha avatar May 25 '22 10:05 achilleasatha

Yeah, happens in Python 3.9 and above. You can convert the .xlsx files to .xls. Also impacts the example.xlsx file on the bittytax GitHub page.

codelbank avatar Jul 25 '22 16:07 codelbank

The plan is to migrate to openpyxl for .xlsx documents, for .xls files xlrd will remain. See #36.

nanonano avatar Jul 25 '22 17:07 nanonano

Hi @achilleasatha, having trouble recreating the issue so I can test the workaround.

Please can you confirm which version of Python 3.9 you are running, also which version of xlrd?

nanonano avatar Jan 24 '23 01:01 nanonano

I also can't read XLSX files with my (old) version of BittyTax. Will try updating everything soon. Python 3.9.6 xlrd 1.2.0

curtailment avatar Mar 06 '23 13:03 curtailment

Hi @curtailment, strange I've also tested python 3.9 with xlrd 1.2.0 and it works fine. Please can you post the exception you're getting?

nanonano avatar Mar 06 '23 14:03 nanonano

Hi @nanonano, By default I just get: ERROR File could not be read: all.xlsx But if I edit bittytax.py to remove the try/catch around transaction_records = do_import(args.filename) then it gives the following:

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\Scripts\bittytax-script.py", line 33, in <module>
    sys.exit(load_entry_point('BittyTax==0.5.0', 'console_scripts', 'bittytax')())
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\bittytax-0.5.0-py3.9.egg\bittytax\bittytax.py", line 98, in main
    transaction_records = do_import(args.filename)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\bittytax-0.5.0-py3.9.egg\bittytax\bittytax.py", line 161, in do_import
    import_records.import_excel(filename)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\bittytax-0.5.0-py3.9.egg\bittytax\import_records.py", line 27, in import_excel
    workbook = xlrd.open_workbook(filename)
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\xlrd-1.2.0-py3.9.egg\xlrd\__init__.py", line 130, in open_workbook
    bk = xlsx.open_workbook_2007_xml(
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\xlrd-1.2.0-py3.9.egg\xlrd\xlsx.py", line 812, in open_workbook_2007_xml
    x12book.process_stream(zflo, 'Workbook')
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\xlrd-1.2.0-py3.9.egg\xlrd\xlsx.py", line 266, in process_stream
    for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator():
AttributeError: 'ElementTree' object has no attribute 'getiterator'

I am using an old version of BittyTax (from Feb 2022). I made some of my own updates to the parsers so haven't upgraded to the latest yet.

EDIT: Just to be clear, my current workaround is making a copy of the XLSX in XLS format every time I want to run bittytax.

curtailment avatar Mar 06 '23 16:03 curtailment

Thanks @curtailment, been having a play and it looks like it only happens if you have defusedxml installed as well.

nanonano avatar Mar 06 '23 17:03 nanonano