jseutter/ofxparse

Read an OFX String instead of a OFX file

jones-chris opened this issue · 4 comments

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

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

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

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