Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ascii' codec can't decode error #129

Open
ffaf1 opened this issue Jul 23, 2021 · 3 comments
Open

'ascii' codec can't decode error #129

ffaf1 opened this issue Jul 23, 2021 · 3 comments

Comments

@ffaf1
Copy link

ffaf1 commented Jul 23, 2021

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
-->

@egh
Copy link
Owner

egh commented Jul 27, 2021

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.

@ffaf1
Copy link
Author

ffaf1 commented Jul 27, 2021

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)

@egh
Copy link
Owner

egh commented Aug 3, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants