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

PC API login/auth errors starting 11/17/2021 #20

Open
ianvanhoven opened this issue Nov 19, 2021 · 21 comments
Open

PC API login/auth errors starting 11/17/2021 #20

ianvanhoven opened this issue Nov 19, 2021 · 21 comments

Comments

@ianvanhoven
Copy link

Starting ~2d ago (17-NOV), started getting these Personal Capital API login/auth errors...

% ./wx.ad.py ro
Traceback (most recent call last):
File "./wx.ad.py", line 60, in <module>
pc.login( pc_cred_user , pc_cred_pass ) ;
File "/usr/local/lib/python3.4/site-packages/personalcapital/personalcapital.py", line 44, in login
raise Exception()
Exception

...on code from this library that has run flawlessly for well over a year...

34 def login(self, username, password):
35 initial_csrf = self.__get_csrf_from_home_page(base_url)
36 csrf, auth_level = self.__identify_user(username, initial_csrf)
37
38 if csrf and auth_level:
39 self.__csrf = csrf
40 if auth_level != AuthLevelEnum.USER_REMEMBERED:
41 raise RequireTwoFactorException()
42 self.__authenticate_password(password)
43 else:
44 raise Exception()

Is anyone else experiencing this and/or have a fix/workaround? Tried disabling 2FA, no dice. Have logged a support case with PC but not holding my breath.

Thanks!
Ian

@coding4z
Copy link

+1 with the exact same errors starting on 11/17/2021

@ianvanhoven
Copy link
Author

Thx for verifying @khite1983 ... good in a way to know it's not specific/limited to me. Maybe chuck a Support case in as well.

(Unfortunately they didn't give me a case # for you to reference ... just an email thread, where I commented just now about your confirmation that this is broken.)

I'm dusting off my Plaid credentials & exploring that as an alternative if PC Support doesn't engage.

@bhpetersheim
Copy link

Same issue here as well.

@UnusualPi
Copy link

UnusualPi commented Nov 20, 2021

Looks like update in cloudflare, a small homepage structure change, and API payloads. My solution here (new dependency added, cloudscraper): pull request #21

@bpassini12
Copy link

same issue.

@ianvanhoven
Copy link
Author

ianvanhoven commented Nov 21, 2021 via email

@UnusualPi
Copy link

@ianvanhoven it really depends on your implementation, but you'll definitely have to install cloudscraper. For the code changes in the personalcapital.py file, you could either edit directly in your python site-packages directory or you could just download the file, include in your script directory, and make the modifications on that file. I'd recommend the latter, when you use import in python it looks for files in the same directory before looking in site-packages. Hope that helps!

@willyiwei
Copy link

Thanks, @UnusualPi. I applied your fix and it resolved the login error issue on my end. I had to upgrade a couple of required package versions to make it fully work though. Thanks again for the solution!

@banool
Copy link

banool commented Nov 24, 2021

Was about to come here and make a similar pull request! Thanks for making this. For those coming along trying to fix this for themselves, run the following (assuming you're using requirements.txt):

pip uninstall personalcapital -y
pip install git+git://github.com/UnusualPi/personalcapital.git@cd0c88f78912c928ad8fafcce05864a43d914d54
pip freeze > requirements.txt
echo 'git+git://github.com/UnusualPi/personalcapital.git@cd0c88f78912c928ad8fafcce05864a43d914d54' >> requirements.txt

Note that there are breaking changes, such as authenticate_password requiring username now, so make sure to update your use of the library if you switch over.

@ianvanhoven
Copy link
Author

ianvanhoven commented Dec 1, 2021 via email

@ianvanhoven
Copy link
Author

ianvanhoven commented Dec 1, 2021 via email

@ecoen66
Copy link

ecoen66 commented Dec 24, 2021

I wonder if @haochi would be willing to assign ownership of this repo to another dev so that we could add this fix?

@elstevega
Copy link

elstevega commented Jan 3, 2022

Ok, I'm super close to getting this working...Getting the prompt for the verification code from Personal Capital, but when I click the 'Verify' button am getting the response:
Failed to call service configurator/configure.authenticate_password() missing 1 required positional argument: 'password'

Any thoughts?

thanks

EDIT: It's line 74 of sensor.py

result = pc.authenticate_password(config.get(CONF_PASSWORD))

@deusxanima
Copy link

@elstevega You'll have to update the file you're running the main scripts in to include the additional parameter. UnusualPi's fix added an additional parameter that gets passed in and which is expected by the PersonalCapital parent class in the personalcapital module.

In your case above, you're passing in the password that you get with (config.get(CONF_PASSWORD) but because it's the only thing being passed in and not being passed in explicitly the parent class is treating is as the first parameter (username) and saying you're missing the password.

To fix it you can modify your authenticate_password method to pass in the email as well. I'm not sure what your actual script file looks like but you should be able to do something like result = pc.authenticate_password(config.get(CONF_EMAIL),config.get(CONF_PASSWORD)) (assuming you're able to reference both your email and password with config.get).

@elstevega
Copy link

@AHARIC - thanks for the info - that did the trick. (I was close...)
:)

@elstevega
Copy link

Argh, I spoke too soon. While the initial SMS validation piece now works (thanks @AHARIC ), when I reboot the HA server, it loses the connection info and kicks back the below in the log file:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/personalcapital/sensor.py", line 130, in setup_platform
    pc.login(config.get(CONF_EMAIL), config.get(CONF_PASSWORD))
  File "/usr/local/lib/python3.9/site-packages/personalcapital/personalcapital.py", line 44, in login
    raise Exception()
Exception

That bit of code is the update from UnusualPi...code block below - any thoughts? Thanks so much in advance!!

    def login(self, username, password):
        initial_csrf = self.__get_csrf_from_home_page(base_url)
        csrf, auth_level = self.__identify_user(username, initial_csrf)

        if csrf and auth_level:
            self.__csrf = csrf
            if auth_level != AuthLevelEnum.USER_REMEMBERED:
                raise RequireTwoFactorException()
            result = self.__authenticate_password(username, password).json()
            if getSpHeaderValue(result, SUCCESS_KEY) == False:
                raise LoginFailedException(getErrorValue(result))
        else:
            raise LoginFailedException()

@willyiwei
Copy link

@elstevega , I might be overlooking something, but judging by the Traceback infomation you pasted above, it seems like your code is still using the original version of the personalcapital.py from pip install, because the file path showed as:

File "/usr/local/lib/python3.9/site-packages/personalcapital/personalcapital.py"

That would still cause the issue that we are tracking here in this issue #20.
Do you mind to double check your project folder and your python path. You may want to make sure your code is using the UnusualPi's updated personalcapital.py

@elstevega
Copy link

@elstevega , I might be overlooking something, but judging by the Traceback infomation you pasted above, it seems like your code is still using the original version of the personalcapital.py from pip install, because the file path showed as:

File "/usr/local/lib/python3.9/site-packages/personalcapital/personalcapital.py"

That would still cause the issue that we are tracking here in this issue #20. Do you mind to double check your project folder and your python path. You may want to make sure your code is using the UnusualPi's updated personalcapital.py

No problem & thanks for your response. Uninstalled/re-installed everything just to make sure.
I cleared out the session on the personal capital website & re-authenticated. gonna reboot the HA server tomorrow & see what happens

@willyiwei
Copy link

Sounds good, @elstevega. And I had a brief glance of your other reply in my email inbox and from there I got some hints about what your issue might be.

When you get a chance to check it again, you may want to pay attention to the two different python lib paths below:

/usr/lib/python3.9/site-packages/personalcapital.py

v.s.

/usr/local/lib/python3.9/site-packages/personalcapital.py

By default, I think pip install the packages into /user/loca/lib/python3.9/....

Make sure you replace this file in the correct lib path. I use virtualenv so my lib file is inside my venv/ folder instead of global /usr/local/lib

You can use this command line to check the information about your pip installed personalcapital package:

$ pip show PersonalCapital

Then it will give you a Location to your personalcapital package installation on your host.

Hope it helps.

@elstevega
Copy link

Thanks @willyiwei - looks like I'm surviving reboots & all is well - thanks to all here for lending a hand.

@banool
Copy link

banool commented Apr 13, 2023

I was using the fork from @UnusualPi but it looks like they deleted it. I made those same changes in my own fork here: https://github.com/banool/personalcapital..

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

10 participants