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

Read an OFX String instead of a OFX file #159

Open
jones-chris opened this issue Aug 28, 2020 · 4 comments
Open

Read an OFX String instead of a OFX file #159

jones-chris opened this issue Aug 28, 2020 · 4 comments

Comments

@jones-chris
Copy link

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

@leogregianin
Copy link

leogregianin commented Dec 3, 2020

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

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

@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
Copy link
Owner

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

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

4 participants