ofxparse icon indicating copy to clipboard operation
ofxparse copied to clipboard

Read an OFX String instead of a OFX file

Open jones-chris opened this issue 4 years ago • 4 comments

It would be helpful if this library could read an OFX string instead of only OFX files.

jones-chris avatar Aug 28 '20 00:08 jones-chris

Can you try this:

from io import BytesIO
from ofxparse import OfxParser

ofx_string = """OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
(...)
"""

f = BytesIO(ofx_string)
ofx = OfxParser.parse(f)

# Account
account = ofx.account
account.routing_number

leogregianin avatar Dec 03 '20 14:12 leogregianin

i tried but this TypeError occurs.. TypeError Traceback (most recent call last) in ----> 1 f = BytesIO(ofx_string) 2 ofx = OfxParser.parse(f)

TypeError: a bytes-like object is required, not 'str' ​

valinolucas407 avatar Apr 01 '21 23:04 valinolucas407

@valinolucas407, try to encode your string, like this:

from io import BytesIO
from ofxparse import OfxParser

ofx_string = """OFXHEADER:100
DATA:OFXSGML
VERSION:102
SECURITY:NONE
(...)
"""

ofx = OfxParser.parse(BytesIO(ofx_string.encode('utf-8')))

account = ofx.account
account.routing_number

leogregianin avatar Apr 03 '21 16:04 leogregianin

Thanks @leogregianin for explaining this. @valinolucas407, did you get your code to work?

jseutter avatar May 31 '21 02:05 jseutter