fbchat-dev / fbchat

Facebook Chat (Messenger) for Python
https://fbchat.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.19k stars 412 forks source link

Login Issue with FBChat #619

Open AdrienR17 opened 4 years ago

AdrienR17 commented 4 years ago

Description of the problem

Hello, Trying to loggin with FBChat but I always have the following error despite on my FB account I've a notification that "someone try to connect". Could you help me please?

Code to reproduce

username = "MY_EMAIL"
password = "MY_PASSWORD"
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36'
client = fbchat.Client(username, password, user_agent=user_agent, max_tries = 1)

Traceback

AttributeError                            Traceback (most recent call last)
<ipython-input-2-e46c48d383f0> in <module>
      6 
      7 user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36'
----> 8 client = fbchat.Client(username, password, user_agent=user_agent, max_tries = 1)

~\Anaconda3\lib\site-packages\fbchat\_client.py in __init__(self, email, password, user_agent, max_tries, session_cookies, logging_level)
    101             or not self.isLoggedIn()
    102         ):
--> 103             self.login(email, password, max_tries, user_agent=user_agent)
    104 
    105     """

~\Anaconda3\lib\site-packages\fbchat\_client.py in login(self, email, password, max_tries, user_agent)
    207                     password,
    208                     on_2fa_callback=self.on2FACode,
--> 209                     user_agent=user_agent,
    210                 )
    211                 self._uid = self._state.user_id

~\Anaconda3\lib\site-packages\fbchat\_state.py in login(cls, email, password, on_2fa_callback, user_agent)
    149 
    150         if is_home(r.url):
--> 151             return cls.from_session(session=session)
    152         else:
    153             raise _exception.FBchatUserError(

~\Anaconda3\lib\site-packages\fbchat\_state.py in from_session(cls, session)
    186         else:
    187             # Fall back to searching with a regex
--> 188             fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1)
    189 
    190         revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])

AttributeError: 'NoneType' object has no attribute 'group'

Environment information

fbchat 1.9.7

Solite7 commented 4 years ago

Go to this file ...\site-packages\fbchat\_state.py Replace the following line FB_DTSG_REGEX = re.compile(r'name="fb_dtsg" value="(.*?)"') To this FB_DTSG_REGEX = re.compile(r'"fb_dtsg","value":"(.*?)"')

AdrienR17 commented 4 years ago

Despite the modification, nothing changes, I got the same error

atbuy commented 4 years ago

For me, that fixed the error, but it created a new one.

Traceback (most recent call last):
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python37\lib\site-packages\fbchat\_client.py", line 209, in login
    user_agent=user_agent,
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python37\lib\site-packages\fbchat\_state.py", line 151, in login
    return cls.from_session(session=session)
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python37\lib\site-packages\fbchat\_state.py", line 190, in from_session
    revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
IndexError: list index out of range
Solite7 commented 4 years ago

Maybe its because you are using an unsupported browser. I got the same error, so I added a custom user-agent. This fixed the error for me

from fbchat import Client

ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"
client = Client('<email>', '<password>', user_agent=ua)
Lolmc0587 commented 4 years ago

Python\Python38-32\lib\site-packages\fbchat\_state.py", line 188, in from_session fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) AttributeError: 'NoneType' object has no attribute 'group'

Replace the following line FB_DTSG_REGEX = re.compile(r'name="fb_dtsg" value="(.*?)"') To this FB_DTSG_REGEX = re.compile(r'"fb_dtsg","value":"(.*?)"')

i already do but the err still apear

cbdelavenne commented 3 years ago

I'm having the same issue as you @lolmc1982

abirbensoltane commented 3 years ago

prob solved here https://github.com/fbchat-dev/fbchat/issues/615

cbdelavenne commented 3 years ago

Thanks Abir, I'll check it out.

On Sun., Jan. 17, 2021, 19:07 Abir Ben Soltane, notifications@github.com wrote:

prob solved here

615 https://github.com/fbchat-dev/fbchat/issues/615

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/fbchat-dev/fbchat/issues/619#issuecomment-761905118, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADZIY3SKHH73QTHWZD6AYRLS2N3SLANCNFSM4S5TCM2Q .