fbchat: Can't login in v2.0.0a3 but can in previous versions
Description of the problem
Attempting to login using fbchat v2.0.0a3 throws an error, see Traceback below. I can login as expected using 2.0.0a2 and 1.9.6…
Someone else has had the same problem, and could also solve by using v2.0.0a2, see https://github.com/carpedm20/fbchat/issues/581
Seems related to the solution to https://github.com/carpedm20/fbchat/issues/413, in particular commit https://github.com/carpedm20/fbchat/commit/079d4093c4f0febf004c6cf8f6972f157833a4f7
Code to reproduce
import fbchat
session = fbchat.Session.login("<username snipped>", "<password snipped>")
Traceback
Traceback (most recent call last):
File "hello.py", line 4, in <module>
session = fbchat.Session.login("<username snipped>", "<password snipped>")
File "/Users/matt/programming/python/patrick2/venv/lib/python3.7/site-packages/fbchat/_session.py", line 290, in login
raise _exception.NotLoggedIn(error)
fbchat.NotLoggedIn: Password Forgot account?
Environment information
- Python version 3.7.7
fbchatversion 2.0.0a3 (installed withpip install fbchat==2.0.0a3)
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 16 (12 by maintainers)
The code above is a bit bloated to be committed I reckon. You’re better off just scraping the
_js_datrcookie from a new session onmessenger.com.Add it to your session cookies using:
requests.utils.add_dict_to_cookiejar(session.cookies, {'_js_datr': js_datr})orsession.cookies.set("_js_datr", js_datr, domain=".messenger.com")Note to my future self: I managed to get the same error page as you people by inserting an old
datrcookie, using that I should be able to improve the error message parsing.Thanks for the details @xaadu, they’ve been really helpful!
Like you said, the
actcookie is generated using JavaScript (I’ve seen it as well 😉). To me, it seems to be a combination of the current timestamp (in milliseconds) and a number indicating which number request this was (we set this to0always, might not be correct?).I’ve added this to the login code, see d65094653154ebecc5f3fd018164a0459b5d259c, and released
v2.0.0a5, so please try that out and see if it works for you now.I’ve been trying for 2 hours and nothing happened! I’ve tried with sending every single details, but it can’t log in.
I’ve added dynamic details to the session so that every details gets up to date perfectly
Still, can’t login! NB: value of the key “lgndim” gets empty string, don’t know why, so I’ve tried adding custom value to that, still doesn’t work! (Maybe it is generated after the page load using JS)
After trying to log in many times, I’ve found that, a cookie generates and then logs in to messenger named “act” followed by a number value, and that is the main problem. I have no idea where the cookie sent from! Here’s an example: After going to login page: the cookies are -
and this cookie is sent by browser on login attempt in browser -
See, last act just appeared! When this cookie is available (copied from browser and sent request with the cookie) and I send request to login, it goes to the 2fa page, but if the act is not available in the cookie, then It redirects to the error page @wetmore provided! I’m noob at coding so I don’t know what happens here! I’ve told you everything I could feel about this! And one more thing, the act numbers first some digits matches with the “datr” cookie and more matches with the max-age or something from received headers strict-transport-security maybe! I’m not sure!
I’ve explained everything I could get on this login, I’ll try to explore more If I get free time! I don’t know if anything I wrote could help! Please tell me if i should try another way or something!