Login Issue with FBChat
AdrienR17 opened this issue · 8 comments
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
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":"(.*?)"')
Despite the modification, nothing changes, I got the same error
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
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)
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
I'm having the same issue as you @lolmc1982
prob solved here
#615