fbchat
fbchat copied to clipboard
Login failed
I tried this and if i put right credentials it always write that i have wrong password Used example echo bot
Environment information
- Python version - 3.7.3
-
fbchat
version - that one from pip install fbchat Package Version
aenum 2.1.2 attrs 18.2.0 beautifulsoup4 4.7.1 certifi 2019.6.16 chardet 3.0.4 fbchat 1.7.0 idna 2.8 pip 19.1.1 requests 2.22.0 setuptools 40.8.0 soupsieve 1.9.2 urllib3 1.25.3
I could reproduce this the first few times but now I can't and I login successfully.
Anyway, here's the exception when it failed
Logging in [email protected]... Attempt #1 failed, retrying Traceback (most recent call last): File "/usr/local/lib/python3.5/dist-packages/fbchat/_client.py", line 210, in login user_agent=user_agent, File "/usr/local/lib/python3.5/dist-packages/fbchat/_state.py", line 153, in login "(Failed on url: {})".format(r.url) fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/gettingstarted/?_rdr)
"/gettingstarted" is the url for a page with some intructions for setting up your account (like adding contacts or a mobile number), it only appears on new accounts so it goes away after a few attempts. If you want to make it go away, you have to visit the url directly and click next a few times, on next start it should log in correctly
I now think that detecting this url (maybe skipping it automatically?) might be a good idea, I'll try to code that if I have the time
Hi There!
I've a similar issue. However I want to move my fbchat program to another computer with the same credentials. The login is successful at my original place (old computer), and it doesn't login on the other one (new computer).
Any idea?
Thank you: FeZ.
Herre is the error message:
Traceback (most recent call last):
File "fbnotifications.py", line 105, in
Hi @FeZoli. The best suggestion I can give you is to try copying the session cookies over. An example would be something like this:
# On the old computer, run
import json
import fbchat
client = fbchat.Client(USER, PASSWORD)
cookies = client.getSession()
with open("session.json", "w") as f:
json.dump(cookies, f)
# After copying the session.json file to the new computer, run
import json
import fbchat
with open("session.json") as f:
cookies = json.load(f)
client = fbchat.Client(USER, PASSWORD, session_cookies=cookies)
the post request url is different for login
in _state.py:
@classmethod
def login(cls, email, password, on_2fa_callback, user_agent=None):
session = session_factory(user_agent=user_agent)
soup = find_input_fields(session.get("https://m.facebook.com/").text)
data = dict(
(elem["name"], elem["value"])
for elem in soup
if elem.has_attr("value") and elem.has_attr("name")
)
data["email"] = email
data["pass"] = password
data["login"] = "Log In"
r = session.post("https://m.facebook.com/login/device-based/regular/login/?login_attempt=1", data=data)
i login successfully with this post url i found
r = session.post("https://m.facebook.com/login/device-based/regular/login/?login_attempt=1", data=data)
but pullchannel not working so idk how to get retrieve messages.
Hi @FeZoli. The best suggestion I can give you is to try copying the session cookies over. An example would be something like this:
# On the old computer, run import json import fbchat client = fbchat.Client(USER, PASSWORD) cookies = client.getSession() with open("session.json", "w") as f: json.dump(cookies, f) # After copying the session.json file to the new computer, run import json import fbchat with open("session.json") as f: cookies = json.load(f) client = fbchat.Client(USER, PASSWORD, session_cookies=cookies)
Many thanks, but my client doesn't work anymore in any of my instances. So, I don't have a session cookie.
I have the same problem... The error message finishes like this:
fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/checkpoint/?_rdr)
For some reason it keeps redirecting me to the identity check, is there any solution to this? It is really annoying because it also affects my browser...
Happen to me too. this is my code.
from fbchat import Client
import json
from fbchat.models import *
cookies = {}
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36'
try:
with open('session.json','r') as f:
cookies = json.load(f)
except:
pass
if cookies == {} :
email = input('email : ')
password = input('password : ')
client = Client(email,password,user_agent=user_agent)
else :
print('found cookies')
client = Client('','',user_agent=user_agent,session_cookies=cookies)
print("Complete")
with open('session.json','w') as f:
json.dump(client.getSession(),f)
First time log in everything is fine.
email : [email protected]
password : mypassword
Logging in [email protected]...
Please enter your 2FA code --> 8596 8714
Submitting 2FA code.
Complete
Login of [email protected] successful.
session.json is also has data
Second time
found cookies
Logging in ...
Traceback (most recent call last):
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/main.py", line 20, in <module>
client = Client('','',user_agent=user_agent,session_cookies=cookies)
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/python/lib/python3.7/site-packages/fbchat/_client.py", line 104, in __init__
self.login(email, password, max_tries, user_agent=user_agent)
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/python/lib/python3.7/site-packages/fbchat/_client.py", line 202, in login
raise FBchatUserError("Email and password not set")
fbchat._exception.FBchatUserError: Email and password not set
@chalermporn17PPA, this might be a separate issue; can you try adding the following code and test it again?
import logging
logging.basicConfig(level=logging.DEBUG)
@chalermporn17PPA, this might be a separate issue; can you try adding the following code and test it again?
import logging logging.basicConfig(level=logging.DEBUG)
This is my program's log. I tried delete session.json and relogin. I can log in by email/password but can't by cookies file.
found cookies
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.facebook.com:443
DEBUG:urllib3.connectionpool:https://www.facebook.com:443 "GET / HTTP/1.1" 302 0
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): web.facebook.com:443
DEBUG:urllib3.connectionpool:https://web.facebook.com:443 "GET /?_rdc=1&_rdr HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): m.facebook.com:443
DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET /login.php?login_attempt=1 HTTP/1.1" 302 0
Logging in ...
INFO:client:Logging in ...
Traceback (most recent call last):
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/main.py", line 22, in <module>
client = Client('','',user_agent=user_agent,session_cookies=cookies)
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/python/lib/python3.7/site-packages/fbchat/_client.py", line 104, in __init__
self.login(email, password, max_tries, user_agent=user_agent)
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/python/lib/python3.7/site-packages/fbchat/_client.py", line 202, in login
raise FBchatUserError("Email and password not set")
fbchat._exception.FBchatUserError: Email and password not set
Hmm, might be something wrong with .isLoggedIn
. Can you try a different user agent, for example "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"
?
@chalermporn17PPA, this might be a separate issue; can you try adding the following code and test it again?
import logging logging.basicConfig(level=logging.DEBUG)
This is my program's log. I tried delete session.json and relogin. I can log in by email/password but can't by cookies file.
found cookies DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.facebook.com:443 DEBUG:urllib3.connectionpool:https://www.facebook.com:443 "GET / HTTP/1.1" 302 0 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): web.facebook.com:443 DEBUG:urllib3.connectionpool:https://web.facebook.com:443 "GET /?_rdc=1&_rdr HTTP/1.1" 200 None DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): m.facebook.com:443 DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET /login.php?login_attempt=1 HTTP/1.1" 302 0 Logging in ... INFO:client:Logging in ... Traceback (most recent call last): File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/main.py", line 22, in <module> client = Client('','',user_agent=user_agent,session_cookies=cookies) File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/python/lib/python3.7/site-packages/fbchat/_client.py", line 104, in __init__ self.login(email, password, max_tries, user_agent=user_agent) File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/python/lib/python3.7/site-packages/fbchat/_client.py", line 202, in login raise FBchatUserError("Email and password not set") fbchat._exception.FBchatUserError: Email and password not set
Did you, by any chance, closed the client?
Hmm, might be something wrong with
.isLoggedIn
. Can you try a different user agent, for example"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36"
?
I tried it. get same error.
found cookies
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): www.facebook.com:443
DEBUG:urllib3.connectionpool:https://www.facebook.com:443 "GET / HTTP/1.1" 302 0
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): web.facebook.com:443
DEBUG:urllib3.connectionpool:https://web.facebook.com:443 "GET /?_rdc=1&_rdr HTTP/1.1" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): m.facebook.com:443
DEBUG:urllib3.connectionpool:https://m.facebook.com:443 "GET /login.php?login_attempt=1 HTTP/1.1" 302 0
Logging in ...
INFO:client:Logging in ...
Traceback (most recent call last):
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/main.py", line 22, in <module>
client = Client('','',user_agent=user_agent,session_cookies=cookies)
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/python/lib/python3.7/site-packages/fbchat/_client.py", line 104, in __init__
self.login(email, password, max_tries, user_agent=user_agent)
File "/home/chalermporn/Desktop/PythonPJ/Pia_BOT/python/lib/python3.7/site-packages/fbchat/_client.py", line 202, in login
raise FBchatUserError("Email and password not set")
fbchat._exception.FBchatUserError: Email and password not set
@lengors I don't know if I closed it. How can I check it ? My code has only I posted.
@lengors I don't know if I closed it. How can I check it ? My code has only I posted.
Hmm, if the code that u posted is everything that u have, then u didn't call client.close(), which means it should work...
@chalermporn17PPA Do you have an up to date version of fbchat? Also, try to not specify the user agent when cookies are detected
@chalermporn17PPA Do you have an up to date version of fbchat? Also, try to not specify the user agent when cookies are detected
try to not specify the user agent when cookies are detected
is Work !! Thank you very much.
@chalermporn17PPA Do you have an up to date version of fbchat? Also, try to not specify the user agent when cookies are detected
try to not specify the user agent when cookies are detected
is Work !! Thank you very much.
U're welcome 🙂
my account getting locked on sending new message can you tell what to write in code to fix it
from fbchat import Client
from fbchat.models import *
client = Client('[email protected]', 'xxx@123')
message = input('Enter the Message')
userid = input('Enter the UserId')
client.send(Message(text= message), thread_id=userid, thread_type=ThreadType.USER)
client.logout()
is there anyway how to login if we got a checkpoint ? I have tried several times but still error :( this is my new laptop :(, my old laptop has been damaged and I could not get the session:(
fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/checkpoint/?_rdr)
There’s 2different issues in here which would probably make more sense being split up.
- getting checkpoint
- 2FA and user agent.
Assuming we’re talking about 1), you need to clear the checkpoint on where you’re running the bot using a browser (see #225 )
Not sure if this is the same error but..
Problems started about the same time as Facebook stopped allowing users to use messenger without facebook.
INFO:root:Starting Plexbot. DEBUG:asyncio:Using selector: EpollSelector INFO:fbchat.client:Logging in redacted... INFO:fbchat.client:Login of redacted successful. INFO:fbchat.client:Listening with long polling... DEBUG:fbchat.request:GET https://0-edge-chat.facebook.com/active_ping?seq=0&channel=p_100012375879147&clientid=redacted&partition=-2&cap=0&uid=redacted&viewer_uid=100012375879147&state=active&__a=1&__req=1&__rev=1001614808&fb_dtsg=AQGzh6n0yYSO:AQHRWNpFmFZD DEBUG:fbchat.request:POST /api/graphqlbatch/?method=GET&response_format=json&queries={"q0": {"doc_id": "1349387578499440", "query_params": {"limit": 1, "tags": ["INBOX"], "before": null, "includeDeliveryReceipts": false, "includeSeqID": true}}}&__a=1&__req=2&__rev=1001614808&fb_dtsg=AQGzh6n0yYSO:AQHRWNpFmFZD DEBUG:fbchat.util:{'t': 'pong'} DEBUG:fbchat.request:GET https://0-edge-chat.facebook.com/pull?seq=0&msgs_recv=0&clientid=redacted&state=active&__a=1&__req=3&__rev=1001614808&fb_dtsg=AQGzh6n0yYSO:AQHRWNpFmFZD DEBUG:hbmqtt.client.plugins:Loading plugins for namespace hbmqtt.client.plugins DEBUG:hbmqtt.client.plugins: Loading plugin packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin DEBUG:hbmqtt.client.plugins: Initializing plugin packet_logger_plugin = hbmqtt.plugins.logging:PacketLoggerPlugin DEBUG:hbmqtt.client.plugins: Plugin packet_logger_plugin ready DEBUG:hbmqtt.client:Connect to: wss://edge-chat.facebook.com/chat?region=atn&sid=901811145520965 WARNING:hbmqtt.client:Connection failed: TypeError("create_connection() got an unexpected keyword argument 'ping_timeout'",) DEBUG:hbmqtt.client:Reconnecting with session parameters: Session(clientId=mqttwsclient, state=new) DEBUG:fbchat.util:{'t': 'lb', 'lb_info': {'sticky': '2178', 'pool': 'rash0c01_chatproxy-regional'}} DEBUG:fbchat.request:GET https://0-edge-chat.facebook.com/active_ping?seq=0&channel=p_100012375879147&clientid=redacted&partition=-2&cap=0&uid=redacted&sticky_token=2178&sticky_pool=rash0c01_chatproxy-regional&viewer_uid=redacted&state=active&__a=1&__req=4&__rev=1001614808&fb_dtsg=AQGzh6n0yYSO:AQHRWNpFmFZD DEBUG:fbchat.util:{'t': 'pong'} DEBUG:fbchat.request:GET https://0-edge-chat.facebook.com/pull?seq=0&msgs_recv=0&sticky_token=2178&sticky_pool=rash0c01_chatproxy-regional&clientid=redacted&state=active&__a=1&__req=5&__rev=1001614808&fb_dtsg=AQGzh6n0yYSO:AQHRWNpFmFZD DEBUG:fbchat.util:{'t': 'fullReload', 'seq': 1, 'u': redacted, 'ms': [{'type': 'qprimer', 'made': '1579224998409'}]} DEBUG:fbchat.request:GET https://0-edge-chat.facebook.com/active_ping?seq=1&channel=p_100012375879147&clientid=redacted&partition=-2&cap=0&uid=redacted&sticky_token=2178&sticky_pool=rash0c01_chatproxy-regional&viewer_uid=redacted&state=active&__a=1&__req=6&__rev=1001614808&fb_dtsg=AQGzh6n0yYSO:AQHRWNpFmFZD DEBUG:fbchat.util:{'t': 'pong'} DEBUG:fbchat.request:GET https://0-edge-chat.facebook.com/pull?seq=1&msgs_recv=0&sticky_token=2178&sticky_pool=rash0c01_chatproxy-regional&clientid=redacted&state=active&__a=1&__req=7&__rev=1001614808&fb_dtsg=AQGzh6n0yYSO:AQHRWNpFmFZD
INFO:root:Starting Plexbot. INFO:fbchat.client:Logging in redacted... INFO:fbchat.client:Login of redacted successful. INFO:fbchat.client:Listening with long polling... WARNING:hbmqtt.client:Connection failed: TypeError("create_connection() got an unexpected keyword argument 'ping_timeout'",) WARNING:hbmqtt.client:Reconnection attempt failed: TypeError("create_connection() got an unexpected keyword argument 'ping_timeout'",)
Hi @kragebein, my initial assesment is that you have a wrong dependency.
But it looks like you're using fbchat-asyncio
, so please continue any further conversation there 😉
I can't login with or without cookies.
Code I'm using:
def login_logout():
cookies = {}
try:
# Load the session cookies
if os.path.isfile('session.json'):
with open('session.json', 'r') as f:
cookies = json.load(f)
except:
os.remove('session.json')
# If it fails, never mind, we'll just login again
# client = CustomClient(email, password, max_tries=1)
if((not cookies) != True):
client = CustomClient(email, password, session_cookies=cookies, user_agent=user_agent, max_tries=1)
else:
client = CustomClient(email, password, user_agent=user_agent, max_tries=1)
with open('session.json', 'w') as f:
json.dump(client.getSession(), f)
print("\nProgram Started!\n")
client.listen()
Error I'm getting:
Traceback (most recent call last):
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-pa
ckages\fbchat\_client.py", line 175, in setSession
self._state = State.from_cookies(session_cookies, user_agent=user_agent)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-pa
ckages\fbchat\_state.py", line 208, in from_cookies
return cls.from_session(session=session)
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\lib\site-pa
ckages\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'
I was able to login with the same code 2 days ago from PC. But then was getting the same error (with the same code) on Termux (Android) with Python 3.8.2, but not on PC running Python 3.7.
How to fix this?
I can't login. I clear the checkpoint on my every device and browser. I use python3.7.4 and fbchat1.9.6 and up to date last version with pip. my code example:
from fbchat import Client
from fbchat.models import *
client = Client("****@gmail.com", "****")
print("Own id: {}".format(client.uid))
client.send(Message(text="Hi me!"), thread_id=client.uid, thread_type=ThreadType.USER)
client.logout()
error:
Logging in @gmail.com...
Attempt #1 failed, retrying
Traceback (most recent call last):
File "C:\Users\mote\OneDrive\Desktop\fbchat\venv\lib\site-packages\fbchat_client.py", line 209, in login
user_agent="user_agent",
File "C:\Users\mote\OneDrive\Desktop\fbchat\venv\lib\site-packages\fbchat_state.py", line 153, in login
"(Failed on url: {})".format(r.url)
fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/checkpoint/?_rdr)
Attempt #2 failed, retrying
Traceback (most recent call last):
File "C:\Users\mote\OneDrive\Desktop\fbchat\venv\lib\site-packages\fbchat_client.py", line 209, in login
user_agent="user_agent",
File "C:\Users\mote\OneDrive\Desktop\fbchat\venv\lib\site-packages\fbchat_state.py", line 153, in login
"(Failed on url: {})".format(r.url)
fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/checkpoint/?_rdr)
Attempt #3 failed, retrying
Traceback (most recent call last):
File "C:\Users\mote\OneDrive\Desktop\fbchat\venv\lib\site-packages\fbchat_client.py", line 209, in login
user_agent="user_agent",
File "C:\Users\mote\OneDrive\Desktop\fbchat\venv\lib\site-packages\fbchat_state.py", line 153, in login
"(Failed on url: {})".format(r.url)
fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/checkpoint/?_rdr)
Attempt #4 failed, retrying
Traceback (most recent call last):
File "C:\Users\mote\OneDrive\Desktop\fbchat\venv\lib\site-packages\fbchat_client.py", line 209, in login
user_agent="user_agent",
File "C:\Users\mote\OneDrive\Desktop\fbchat\venv\lib\site-packages\fbchat_state.py", line 153, in login
"(Failed on url: {})".format(r.url)
fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/checkpoint/?_rdr)
Traceback (most recent call last):
File "c:/Users/mote/OneDrive/Desktop/fbchat/script.py", line 4, in
Thankyou everyone
v.1.9.7 - Can Login but EchoBot() showing connection lost after listening
maybe some fb url have changed
who can fix??
Please enter your 2FA code --> 048113 Submitting 2FA code. Saving browser. Starting Facebook checkup flow. Verifying login attempt. Saving device again. Attempt #3 failed, retrying Traceback (most recent call last): File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_client.py", line 205, in login self._state = State.login( File "/home/Paullux/.local/lib/python3.8/site-packages/fbchat/_state.py", line 153, in login raise _exception.FBchatUserError( fbchat._exception.FBchatUserError: Login failed. Check email/password. (Failed on url: https://m.facebook.com/login/checkpoint/) Please enter your 2FA code -->
How to hacking id