fbchat-dev / fbchat

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

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

Open Mahmoussam opened 4 years ago

Mahmoussam commented 4 years ago

Description of the problem

when running this examle code i can't login and get errors.

Code to reproduce

# Example code
from fbchat import Client
from fbchat.models import *
import logging
logging.basicConfig(level=logging.DEBUG)
client = Client('<mail>', '<pwd>')
print(client.uid)
client.logout()

Traceback

Logging in mhem2014@yahoo.com...
INFO:client:Logging in mhem2014@yahoo.com...
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): m.facebook.com:443
DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET / HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "POST /login.php?login_attempt=1 HTTP/1.1" 302 0
DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET /login/save-device/?login_source=login&refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET /login/save-device/cancel/ HTTP/1.1" 302 0
DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET /?_rdr HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.facebook.com:443
DEBUG:urllib3.connectionpool:https://www.facebook.com:443 "GET / HTTP/1.1" 200 0
Attempt #1 failed, retrying
Traceback (most recent call last):
  File "C:\Users\el safer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fbchat\_client.py", line 209, in login
    user_agent=user_agent,
  File "C:\Users\el safer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fbchat\_state.py", line 149, in login
    return cls.from_session(session=session)
  File "C:\Users\el safer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fbchat\_state.py", line 186, in from_session
    fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1)
AttributeError: 'NoneType' object has no attribute 'group'
ERROR:client:Attempt #1 failed, retrying
Traceback (most recent call last):
  File "C:\Users\el safer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fbchat\_client.py", line 209, in login
    user_agent=user_agent,
  File "C:\Users\el safer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fbchat\_state.py", line 149, in login
    return cls.from_session(session=session)
  File "C:\Users\el safer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\fbchat\_state.py", line 186, in from_session
    fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Environment information

BriniM commented 4 years ago

Can confirm, same issue here with 1.9.6.

ArthurGarnier commented 4 years ago

Same here, tried versions 1.9.{5,6,7}.

trangcongloc commented 4 years ago

I have the same issue recently. In my case the issue only appear when using different user_agent

Working code

from fbchat import Client

client = Client("email", "pswd")

Error code

from fbchat import Client

USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"

client = Client("email", "pswd", user_agent=USER_AGENT)

Traceback

Logging in username...
Please enter your 2FA code --> xxxxxx
Submitting 2FA code.
Saving browser.
Starting Facebook checkup flow.
Verifying login attempt.
Saving device again.
Attempt #1 failed, retrying
Traceback (most recent call last):
  File "/Users/trangcongloc/Desktop/Dev/py-Ins/venv/lib/python3.7/site-packages/fbchat/_client.py", line 209, in login
    user_agent=user_agent,
  File "/Users/trangcongloc/Desktop/Dev/py-Ins/venv/lib/python3.7/site-packages/fbchat/_state.py", line 151, in login
    return cls.from_session(session=session)
  File "/Users/trangcongloc/Desktop/Dev/py-Ins/venv/lib/python3.7/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'
python       3.7.7
fbchat       1.9.7
requests     2.24.0
urllib3      1.25.9
voccer commented 3 years ago

you must delete client.logout(), it work for me

SDS-2704 commented 3 years ago

I am facing the same error while trying to log-in to fbchat.Client. This is obviously despite me entering absolutely correct ID & P/W. It could be because of any latest update in the package, or a user_agent / session (cookies) issue too. Prima-facie, if you think a few adjustments need to be made in the client or state file/s, please let me know, else I shall share the complete code link for your perusal.

Below's the error message. I will be highly grateful, if I can get an idea of where am I going wrong?

Logging in xxxxxx.x.xxxxxx... Attempt #1 failed, retrying Traceback (most recent call last): File "C:\Users\my\Anaconda3\lib\site-packages\fbchat_client.py", line 209, in login user_agent=user_agent, File "C:\Users\my\Anaconda3\lib\site-packages\fbchat_state.py", line 149, in login return cls.from_session(session=session) File "C:\Users\my\Anaconda3\lib\site-packages\fbchat_state.py", line 186, in from_session fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) AttributeError: 'NoneType' object has no attribute 'group'

sroka78 commented 3 years ago

The same here. Started a couple of days ago and no changes in code was done. It "just happened". Someone please help as I'm lost here. The same stuff happens with my "real" code: Example code debug log:

Logging in FBemail@email.com... INFO:client:Logging in FBemail@email.com... DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): m.facebook.com:443 DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET / HTTP/1.1" 200 None DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "POST /login.php?login_attempt=1 HTTP/1.1" 302 0 DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET /home.php?refsrc=https%3A%2F%2Fwww.facebook.com%2F&_rdr HTTP/1.1" 200 None DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.facebook.com:443 DEBUG:urllib3.connectionpool:https://www.facebook.com:443 "GET / HTTP/1.1" 200 0

Traceback (most recent call last): File "simple.py", line 7, in client = Client('FBemail@email.com', 'FBpwd', max_tries=1) File "C:\Users\HP\Anaconda3\lib\site-packages\fbchat_client.py", line 103, in init self.login(email, password, max_tries, user_agent=user_agent) File "C:\Users\HP\Anaconda3\lib\site-packages\fbchat_client.py", line 209, in login user_agent=user_agent, File "C:\Users\HP\Anaconda3\lib\site-packages\fbchat_state.py", line 149, in login return cls.from_session(session=session) File "C:\Users\HP\Anaconda3\lib\site-packages\fbchat_state.py", line 186, in from_session fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) AttributeError: 'NoneType' object has no attribute 'group'

ArthurGarnier commented 3 years ago

I'm trying to figure out what is happening.

In fact in _state.py ; from_session method a "get" on facebook.com return a 200 response but with empty content (Content-Length = 0) : This is not a normal thing, Facebook should return the home page with the login fields.

adns44 commented 3 years ago

I experience this problem too. It started at yesterday evening and my account blocked, Facebook asks my phone number and a picture from me.

ghost commented 3 years ago

I don't know about you guys, but switching back to "old" facebook fixed it for me.

SandsHUN commented 3 years ago

I don't know about you guys, but switching back to "old" facebook fixed it for me.

How do you do that?

ArthurGarnier commented 3 years ago

Can confirm it works with the old facebook... Hope an update soon to support the new one.

You can do that by passing an OLD user agent : client = Client(login, password, user_agent="Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko")

SandsHUN commented 3 years ago

Can confirm it works with the old facebook... Hope an update soon to support the new one.

You can do that by passing an OLD user agent : client = Client(login, password, user_agent="Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko")

It's not working for me...

File "/home/pi/PythonProgramming/ArtemisCore/MessengerListenerAgent.py", line 210, in client = Client("_xxxxxx_@gmail.com", "xxxx__", user_agent="Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko") File "/usr/local/lib/python3.7/dist-packages/fbchat/_client.py", line 103, in init__ self.login(email, password, max_tries, user_agent=user_agent) File "/usr/local/lib/python3.7/dist-packages/fbchat/_client.py", line 209, in login user_agent=user_agent, File "/usr/local/lib/python3.7/dist-packages/fbchat/_state.py", line 149, in login return cls.from_session(session=session) File "/usr/local/lib/python3.7/dist-packages/fbchat/_state.py", line 186, in from_session fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1) AttributeError: 'NoneType' object has no attribute 'group'

atbuy commented 3 years ago

The same problem is happening for me. I think the html was changed and the regex is not working now. Any updates coming soon? I'm still unable to log in, since facebook made the new mode permanent. If there is anything I could help with I would be glad to.