snowskeleton / ynam

Mint-to-YNAB translator
Apache License 2.0
38 stars 0 forks source link

TypeError: MintTransaction.__init__() missing 1 required positional argument: 'id' #35

Closed BabblingBafoon closed 1 year ago

BabblingBafoon commented 1 year ago

I didn't see this in the open or closed issues. I am running macOS Ventura 13.2.1.

I was able to successfully run ynam --quickstart and see/setup my account using 2FA for Mint.

Running ynam for the first time ran for a bit, then spits out a bunch of stuff, with the last line being: TypeError: MintTransaction.__init__() missing 1 required positional argument: 'id'

The full output is:

% ynam
INFO:mintapi:Downloading version 110.0.5481.77 of Chromedriver
INFO:mintapi:Not on Account Selection Screen
INFO:mintapi:Not on Secondary MFA Password Screen
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ynam/main.py", line 24, in main
    mint_transactions = mint_api.get_transactions(start_date=arg('days'))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ynam/mint_api.py", line 48, in get_transactions
    client.authorize(self.cookies(), self.key())
                     ^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ynam/mint_api.py", line 58, in cookies
    return ast.literal_eval(file.read())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 64, in literal_eval
    node_or_string = parse(node_or_string.lstrip(" \t"), mode='eval')
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 0

SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.11/bin/ynam", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ynam/main.py", line 27, in main
    mint_transactions = mint_api.get_transactions(start_date=arg('days'))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ynam/mint_api.py", line 50, in get_transactions
    items = [
            ^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ynam/mint_api.py", line 51, in <listcomp>
    MintTransaction.from_dict(item['fiData']) for item in items
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/ynam/mint_api.py", line 22, in from_dict
    return cls(**{
           ^^^^^^^
TypeError: MintTransaction.__init__() missing 1 required positional argument: 'id'

I ran it again with ynam -x and saw it launch a Chrome browser, login successfully, starts loading the "Overview" page, then eventually the Chrome window disappears. It's only after this that the output referenced above starts to show up in the terminal.

I should add, though probably obvious, the fiirst line only showed up the first time I ran it. INFO:mintapi:Downloading version 110.0.5481.77 of Chromedriver

Thoughts?

snowskeleton commented 1 year ago

This indeed is a new issue!

It looks like something about the response from Mint isn't formatted to ynam's liking, and I'm doing a poor job of validation. Try and manually examine the item['fiData'] object in the return response, anything look fishy?

BabblingBafoon commented 1 year ago

Would that be in a log file somewhere? I didn't see anything in the ~/.ynam folder that looks like a log file, so not sure where to look for what you are asking.

Apologies, but my troubleshooting foo is weak. ๐Ÿ˜‚ I feel lucky and proud that I got this to work at all!

snowskeleton commented 1 year ago

I just added lines 52 and 53 to mint_api.py

...
logger.info(f"Found {len(items)} transactions in Mint.")
[logger.debug(item['fiData']) for item in items]
...

update ynam (pip install -U ynam, or however you installed it the first time), and run it with the debug flag (ynam --debug). This will dump all Mint transactions (and a bunch of other garbage) to your console. For example, one of my transactions looks like

DEBUG:ynam:
{
'id': 'f40c881c-c71d-4e73-83f9-9b3e98ea71b6',
'date': '2022-10-30',
'amount': -59.82,
'description': '<redacted payee name>',
'inferredDescription': '<redacted payee name>',
'inferredCategory': {
    'id': '89369599_102',
    'name': 'Amusement'
}}
BabblingBafoon commented 1 year ago

I updated ynam, which appeared to be successful. I ran it with debug flag and the output seems really strange to me (at least, the parts that show transactions). It was showing transactions from like 2015 and I'm pretty positive they are from my checking account, NOT my Apple Card. That in itself may point to the source of the problem??

The quickstart doesn't ask for choosing the Apple Card from my Mint account... just what to put the transactions in under the YNAB account, which I did.

How can I help fix it grabbing the (seemingly) wrong account inside Mint?

snowskeleton commented 1 year ago

That could indeed be the problem. I mention it somewhere in the README, but basically ynam assumes that you'll only have your Apple Card linked.

As I see it, you could either go about removing the offending transactions from Mint (assuming you don't need them for historical purposes), or you could make a new Intuit account just for use with ynam. I'm more inclined to the second option, as it's best practice to give all your robots unique login credentials.

BabblingBafoon commented 1 year ago

Doh!!! I totally misunderstood that recommendation as only have one "Apple Card" account linked to your Mint account. Now I completely get it and it makes total sense. Honestly, I kind of feel like an idiot for not doing this anyway. Ugh. ๐Ÿ™„ ๐Ÿ˜‚

Sorry man. Thanks for the work on this and helping figure out my mistake. You rock!!

snowskeleton commented 1 year ago

I'm glad it worked! I should probably surface a better error message for this issue in the future.

Don't feel too bad about needing help for this. We've all been there at some point.