kevinjqiu / tangerine

Tangerine Bank scraper
76 stars 13 forks source link

JSONDecodeError on Login #2

Closed coreyjackwilson closed 6 years ago

coreyjackwilson commented 6 years ago

@kevinjqiu,

Summary

Steps to Reproduce

  1. Use example code in /examples
  2. User InteractiveSecretProvider()
  3. Enter user name
  4. Enter correct secret question answer

Expected Result

  1. A session is created

Actual Result

  1. JSON Decode Error

Code

import logging
import pdb
import datetime
from tangerine import TangerineClient, InteractiveSecretProvider
from tangerine.exceptions import UnsupportedAccountTypeForDownload

FROM = datetime.date(2017, 6, 1)
TO = datetime.date(2017, 11, 2)

def __test__():
    pass

if __name__ == '__main__':
    logging.basicConfig(level=logging.INFO)
    secret_provider = InteractiveSecretProvider()
    client = TangerineClient(secret_provider)
    with client.login():
        accounts = [
            acct for acct in client.list_accounts()
            if acct['type'] != 'CREDIT_CARD'
        ]
        for acct in accounts:
            try:
                client.download_ofx(acct, FROM, TO)
            except UnsupportedAccountTypeForDownload as e:
                print(e)

Stack

Traceback (most recent call last):
  File "main.py", line 20, in <module>
    client = TangerineClient(secret_provider)
  File "/Users/XXXX/.pyenv/versions/3.5.0/lib/python3.5/contextlib.py", line 59, in __enter__
    return next(self.gen)
  File "/Users/XXXX/.pyenv/versions/3.5.0/lib/python3.5/site-packages/tangerine/client.py", line 46, in login
    self.login_flow.start()
  File "/Users/XXXX/.pyenv/versions/3.5.0/lib/python3.5/site-packages/tangerine/login.py", line 89, in start
    phrase = self._get_pin_phrase()
  File "/Users/XXXX/.pyenv/versions/3.5.0/lib/python3.5/site-packages/tangerine/login.py", line 59, in _get_pin_phrase
    return r.json()['MessageBody']['Phrase']
  File "/Users/XXXX/.pyenv/versions/3.5.0/lib/python3.5/site-packages/requests/models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "/Users/XXXX/.pyenv/versions/3.5.0/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/Users/XXXX/.pyenv/versions/3.5.0/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/XXXX/.pyenv/versions/3.5.0/lib/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

EDIT: code formatting

kevinjqiu commented 6 years ago

Hi @coreyjackwilson

It still work for my account. Maybe the tangerine server was doing maintenance at the time and returned a splash page? It's hard to say without looking at the response. If you're still experiencing this issue, could you please increase the log level to 'DEBUG' here, and paste the output (obfuscate any personal identifiable information of course)?

like so:

    logging.basicConfig(level=logging.DEBUG)
kevinjqiu commented 6 years ago

@coreyjackwilson Feel free to reopen if it's still an issue for you.

coreyjackwilson commented 6 years ago

I was able to track it down to an issue with my login creds. If I have time, i submit a PR to expose the message instead of just failing on JSONDecode. Thanks for the swift response @kevinjqiu

normcyr commented 5 years ago

@coreyjackwilson I get the same error as you described. Would you mind sharing your workaround?