ledger-autosync icon indicating copy to clipboard operation
ledger-autosync copied to clipboard

'ascii' codec can't decode error

Open ffaf1 opened this issue 4 years ago • 3 comments
trafficstars

I tried to run ledger-autosync today, I got this error

f@extensa:~/media/vcs/ledger-autosync/bin$ ./hledger-autosync ~/download/prova.ofx
Traceback (most recent call last):
  File "./hledger-autosync", line 8, in <module>
    sys.exit(run())
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ledgerautosync/cli.py", line 474, in run
    import_ofx(ledger, args)
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ledgerautosync/cli.py", line 180, in import_ofx
    ofx = OfxSynchronizer.parse_file(args.PATH)
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ledgerautosync/sync.py", line 43, in parse_file
    return OfxParser.parse(ofx_file)
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ofxparse/ofxparse.py", line 396, in parse
    ofx_file = OfxPreprocessedFile(file_handle)
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ofxparse/ofxparse.py", line 160, in __init__
    ofx_string = self.fh.read()
  File "/usr/lib/python3.7/codecs.py", line 504, in read
    newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1041: ordinal not in range(128)

The header of the Ofx file is:

<!--
OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
ENCODING:UTF-8
CHARSET:NONE
COMPRESSION:NONE
OLDFILEUID:NONE
NEWFILEUID:NONE
-->

ffaf1 avatar Jul 23 '21 15:07 ffaf1

Unfortunately this is an issue with ofxparse. However in this case it looks like ofxparse might be ignoring the header because it's inside an XML comment. You might try removing the <!-- and --> bits.

egh avatar Jul 27 '21 04:07 egh

When I delete the lines with <!--- and --> I get this error

f@extensa:~/spool/fineco-movimenti_$ ~/media/vcs/ledger-autosync/bin/./ledger-autosync prova.ofx
Traceback (most recent call last):
  File "/home/f/media/vcs/ledger-autosync/bin/./ledger-autosync", line 8, in <module>
    sys.exit(run())
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ledgerautosync/cli.py", line 474, in run
    import_ofx(ledger, args)
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ledgerautosync/cli.py", line 180, in import_ofx
    ofx = OfxSynchronizer.parse_file(args.PATH)
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ledgerautosync/sync.py", line 43, in parse_file
    return OfxParser.parse(ofx_file)
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ofxparse/ofxparse.py", line 396, in parse
    ofx_file = OfxPreprocessedFile(file_handle)
  File "/home/f/media/vcs/ledger-autosync/lib/python3.7/site-packages/ofxparse/ofxparse.py", line 183, in __init__
    tag_name = re.findall(r'(?i)<([a-z0-9_\.]+)>', token)[0]
IndexError: list index out of range

My ofx was generated from ofxstatement. ofxdump does read it (albeit with some warnings)

(Above message occurred on Line 1, Column 25507)
LibOFX ERROR: OpenSP parser: otherError (misc parse error):
/tmp/libofxtmpeUaPuf:1:25607:E: non SGML character number 194

(Above message occurred on Line 1, Column 25608)
LibOFX ERROR: OpenSP parser: otherError (misc parse error):
/tmp/libofxtmpeUaPuf:1:25608:E: non SGML character number 176

(Above message occurred on Line 1, Column 25609)
LibOFX ERROR: ofxdate_to_time_t():  Unable to convert time, string > is not in proper YYYYMMDDHHMMSS.XXX[gmt offset:tz name] format!
(Above message occurred on Line 1, Column 25712)

ffaf1 avatar Jul 27 '21 08:07 ffaf1

In that case, I'm not sure what's going on :( You might file a bug upstream with ofxparse - I suspect that is where the root issue is. Of course, the file could be bad as well.

egh avatar Aug 03 '21 05:08 egh