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

Login Issue with FBChat #619

Open
AdrienR17 opened this issue Oct 24, 2020 · 8 comments
Open

Login Issue with FBChat #619

AdrienR17 opened this issue Oct 24, 2020 · 8 comments

Comments

@AdrienR17
Copy link

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
Copy link

Solite7 commented Oct 24, 2020

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
Copy link
Author

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

@atbuy
Copy link

atbuy commented Oct 28, 2020

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
Copy link

Solite7 commented Oct 28, 2020

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
Copy link

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
Copy link

I'm having the same issue as you @lolmc1982

@abirbensoltane
Copy link

prob solved here
#615

@cbdelavenne
Copy link

cbdelavenne commented Jan 18, 2021 via email

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

6 participants