fbchat icon indicating copy to clipboard operation
fbchat copied to clipboard

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

Open Mahmoussam opened this issue 5 years ago • 13 comments

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 [email protected]...
INFO:client:Logging in [email protected]...
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

  • Python version:3.7.0
  • fbchat version:1.9.6
  • If relevant, output from $ python -m pip list
absl-py                          0.9.0
aenum                            2.2.3
aiohttp                          3.5.4
alabaster                        0.7.12
altgraph                         0.16.1
amazonify                        0.1
appdirs                          1.4.3
Appium-Python-Client             0.50
APScheduler                      3.6.3
asn1crypto                       0.24.0
astor                            0.8.1
async-timeout                    3.0.1
attrs                            19.3.0
auto-py-to-exe                   2.6.1
Automat                          20.2.0
Babel                            2.7.0
backcall                         0.1.0
beautifulsoup4                   4.6.3
bottle                           0.12.16
bottle-websocket                 0.2.9
bs4                              0.0.1
cachetools                       4.1.0
certifi                          2018.8.24
cffi                             1.12.3
chardet                          3.0.4
Click                            7.0
clipboard                        0.0.4
cloudmersive-convert-api-client  2.4.3
cloudmersive-image-api-client    2.1.5
cloudmersive-ocr-api-client      2.2.1
cloudmersive-validate-api-client 2.1.2
colorama                         0.4.1
ConfigArgParse                   0.11.0
configparser                     3.7.4
constantly                       15.1.0
cryptography                     2.7
cssselect                        1.0.3
cycler                           0.10.0
Cython                           0.29.16
decorator                        4.4.2
distlib                          0.3.0
distro                           1.5.0
Django                           2.2.2
dnspython                        1.16.0
docutils                         0.14
Eel                              0.10.4
entrypoints                      0.3
et-xmlfile                       1.0.1
eventlet                         0.25.0
fake-useragent                   0.1.11
fbchat                           1.9.6
filelock                         3.0.12
flake8                           3.7.7
Flask                            1.0.2
Flask-MySQL                      1.5.1
Flask-SocketIO                   4.1.0
Flask-WTF                        0.14.2
freelancersdk                    0.1.20
future                           0.16.0
gast                             0.3.3
geographiclib                    1.49
geopy                            1.19.0
gevent                           1.4.0
gevent-websocket                 0.10.1
google-api-core                  1.17.0
google-api-python-client         1.8.2
google-auth                      1.14.0
google-auth-httplib2             0.0.3
google-cloud-vision              1.0.0
google-search-results            1.8.1
googleapis-common-protos         1.51.0
googletrans                      2.4.0
greenlet                         0.4.15
grpcio                           1.28.1
guzzle-sphinx-theme              0.7.11
h5py                             2.10.0
hangups                          0.4.9
html5lib                         1.0.1
httplib2                         0.17.3
hyperlink                        19.0.0
idna                             2.7
imagecodecs                      2020.2.18
imageio                          2.8.0
imagesize                        1.1.0
importlib-metadata               1.6.0
imutils                          0.5.3
incremental                      17.5.0
instagram-private-api            1.6.0.0
InstagramAPI                     1.0.2
instaloader                      4.3.1
ipython                          7.14.0
ipython-genutils                 0.2.0
itsdangerous                     1.1.0
jdcal                            1.4.1
jedi                             0.17.0
Jinja2                           2.10.1
joblib                           0.15.1
kamene                           0.32
Keras                            2.0.8
Keras-Applications               1.0.8
Keras-Preprocessing              1.1.2
kiwisolver                       1.1.0
lanscan                          0.9.5
lml                              0.0.9
lxml                             4.3.3
macholib                         1.11
Markdown                         3.2.2
MarkupSafe                       1.1.1
matplotlib                       3.1.1
mccabe                           0.6.1
MechanicalSoup                   0.6.0
mechanize                        0.4.2
monotonic                        1.5
moviepy                          0.2.3.2
mpegdash                         0.2.0
multidict                        4.5.2
mysql-connector                  2.2.9
mysql-connector-python           8.0.15
netaddr                          0.7.19
netifaces                        0.10.9
networkx                         2.4
nltk                             3.4.4
nose                             1.3.7
numpy                            1.16.3
opencv-python                    4.1.1.26
openpyxl                         2.6.2
packaging                        19.0
paho-mqtt                        1.5.0
pandas                           0.24.2
parse                            1.12.0
parsel                           1.5.2
parso                            0.7.0
pbkdf2                           1.3
pdf2image                        1.12.1
pdfminer.six                     20200517
pdftotree                        0.4.0
pefile                           2018.8.8
pickleshare                      0.7.5
Pillow                           6.0.0
pip                              18.0
pocketsphinx                     0.1.15
prompt-toolkit                   3.0.5
Protego                          0.1.16
protobuf                         3.6.1
py2exe                           0.9.2.0
pyaaf2                           1.4.0
pyaes                            1.6.1
pyasn1                           0.4.8
pyasn1-modules                   0.2.8
pyavb                            0.1.0.dev2
pycodestyle                      2.5.0
pycparser                        2.19
pycryptodome                     3.9.7
PyDispatcher                     2.0.5
pyee                             6.0.0
pyexcel                          0.5.13
pyexcel-io                       0.5.17
pyflakes                         2.1.1
pygame                           1.9.4
Pygments                         2.4.2
PyHamcrest                       2.0.2
PyInstaller                      3.6
PyMySQL                          0.9.3
pynput                           1.4.2
pyOpenSSL                        19.0.0
pyparsing                        2.4.0
PyPDF2                           1.26.0
pyperclip                        1.8.0
pyppeteer                        0.0.25
PyQt5                            5.13.0
PyQt5-sip                        12.7.2
pyqt5-tools                      5.13.0.1.5
pyquery                          1.4.0
Pyrogram                         0.17.0.dev0
pyserial                         3.4
PySocks                          1.7.0
pyTelegramBotAPI                 3.6.7
pytesseract                      0.3.3
python-dateutil                  2.8.0
python-dotenv                    0.13.0
python-engineio                  3.8.2
python-nmap                      0.6.1
python-socketio                  4.2.0
python-telegram                  0.11.0
python-telegram-bot              12.4.2
pyttsx3                          2.7
pytz                             2019.1
pyusb                            1.0.2
PyWavelets                       1.1.1
pywin32                          223.1
pywin32-ctypes                   0.2.0
PyX                              0.15
PyYAML                           5.1.1
queuelib                         1.5.0
readlike                         0.1.2
ReParser                         1.4.3
requests                         2.23.0
requests-file                    1.4.3
requests-html                    0.10.0
requests-toolbelt                0.7.0
rsa                              4.0
scapy                            2.4.3
scapy-python3                    0.26
schedule                         0.6.0
scikit-image                     0.17.2
scikit-learn                     0.23.1
scipy                            1.4.1
Scrapy                           2.0.1
selectivesearch                  0.4
selectorlib                      0.16.0
selenium                         3.141.0
selenium-requests                1.3
seleniumbot                      0.1
service-identity                 18.1.0
setuptools                       39.0.1
six                              1.12.0
sklearn                          0.0
snowballstemmer                  1.9.0
sortedcontainers                 2.1.0
SpeechRecognition                3.8.1
Sphinx                           2.1.2
sphinxcontrib-applehelp          1.0.1
sphinxcontrib-devhelp            1.0.1
sphinxcontrib-htmlhelp           1.0.2
sphinxcontrib-jsmath             1.0.1
sphinxcontrib-qthelp             1.0.2
sphinxcontrib-serializinghtml    1.1.3
sqlparse                         0.3.0
statistics                       1.0.3.5
tabula-py                        2.1.0
telebot                          0.0.3
tensorboard                      1.12.2
tensorflow                       1.12.0
termcolor                        1.1.0
tesseract                        0.1.3
texttable                        1.6.1
TgCrypto                         1.2.0
threadpoolctl                    2.0.0
tifffile                         2020.5.11
tldextract                       2.2.1
tornado                          6.0.4
tqdm                             4.11.2
traitlets                        4.3.3
trunofficial                     0.2.4
Twisted                          20.3.0
tzlocal                          2.0.0
UNKNOWN                          0.0.0
uritemplate                      3.0.1
urllib3                          1.23
urwid                            1.3.1
virtualenv                       20.0.18
w3lib                            1.20.0
Wand                             0.6.1
wcwidth                          0.1.9
webencodings                     0.5.1
websocket-client                 0.56.0
websockets                       7.0
Werkzeug                         0.15.2
wheel                            0.34.2
whichcraft                       0.5.2
wifi                             0.3.8
WTForms                          2.2.1
xlrd                             1.2.0
XlsxWriter                       1.2.8
xlutils                          2.0.0
xlwt                             1.3.0
xmltodict                        0.12.0
yarl                             1.3.0
zipcodes                         1.0.5
zipp                             3.1.0
zope.interface                   5.0.2

If you have done any research, include that. Yes i have done a research but the errors seems to be old. i am using IDLE btw.

Mahmoussam avatar Jun 19 '20 20:06 Mahmoussam

Can confirm, same issue here with 1.9.6.

BriniM avatar Jun 24 '20 13:06 BriniM

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

ArthurGarnier avatar Jun 26 '20 17:06 ArthurGarnier

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

trangcongloc avatar Jul 01 '20 12:07 trangcongloc

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

voccer avatar Jul 13 '20 04:07 voccer

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'

SDS-2704 avatar Jul 13 '20 05:07 SDS-2704

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 [email protected]... INFO:client:Logging in [email protected]... 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('[email protected]', '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'

sroka78 avatar Jul 17 '20 21:07 sroka78

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.

ArthurGarnier avatar Aug 23 '20 13:08 ArthurGarnier

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

adns44 avatar Sep 01 '20 13:09 adns44

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

ghost avatar Sep 22 '20 01:09 ghost

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

How do you do that?

SandsHUN avatar Sep 22 '20 12:09 SandsHUN

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")

ArthurGarnier avatar Sep 25 '20 16:09 ArthurGarnier

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[email protected]", "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'

SandsHUN avatar Sep 25 '20 16:09 SandsHUN

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.

atbuy avatar Oct 21 '20 22:10 atbuy