jseutter / ofxparse

Ofx file format parser for Python
http://sites.google.com/site/ofxparse/
MIT License
204 stars 121 forks source link

Read an OFX String instead of a OFX file #159

Open jones-chris opened 4 years ago

jones-chris commented 4 years ago

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

leogregianin commented 3 years ago

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
valinolucas407 commented 3 years ago

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' ​
leogregianin commented 3 years ago

@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
jseutter commented 3 years ago

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