ofxstatement icon indicating copy to clipboard operation
ofxstatement copied to clipboard

Commented header break OFX import process

Open dev590t opened this issue 6 months ago • 4 comments

ofxstatement comment out header in generated OFX file. That doesn't conform to OFX specification. When I try to parse the OFX file with ofxtools, I get a error because OFX file isn't conform.

Manualy uncomment header is a solution, but my purpose is to build a automatic data ingestion pipeline.

So it is possible to add a parameter in configuration to indicate to genenate a more strict OFX file, with header uncommented

dev590t avatar May 09 '25 15:05 dev590t

@dev590t do you mean this?

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

kedder avatar May 09 '25 19:05 kedder

In general, how can I reproduce the problem myself? From what can I tell ofxtools provides ofxget utility, but it doesn't seem to work with files.

kedder avatar May 09 '25 19:05 kedder

That is documentation of ofxtool about parsing OFX file: https://ofxtools.readthedocs.io/en/latest/parser.html#deviations-from-the-ofx-specification:

In [1]: from ofxtools.Parser import OFXTree
In [2]: parser = OFXTree()
In [3]: with open('2015-09_amtd.ofx', 'rb') as f:  # N.B. need to open file in binary mode
   ...:     parser.parse(f)
   ...:
In [4]: parser.parse('2015-09_amtd.ofx')  # Can also use filename directly

If you run the code on a OFX file generated by ofxstatement, the line parser.parse('sample.ofx') of ofxtools will raise:

ofxtools.header.OFXHeaderError: OFX header is malformed:
<!-- 

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

I'm trying to update a accounting tool 's importer, and switch from ofxparse to ofxtools for the parsing, because ofxparse is no longer maintained. But ofxtools expect OFX file follow strictly OFX specification, it isn't the case for OFX file generated by ofxstatement.

dev590t avatar May 09 '25 21:05 dev590t

@kedder ,A other issue I have is when file contains special UTF-8 char, the ofx reader encounter encoding issue, uncommented the header help solve the issue.

What is purpose to have commented header?

I can try to submit a PR. Do you think the default behavior is a uncommented header, then add a parameter in configuration to allow generate commented header, that is a good solution?

dev590t avatar May 31 '25 18:05 dev590t