fbchat-dev / fbchat

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

Client.search_for_threads hangs on connecting to the socket for ever #577

Open saavedra29 opened 4 years ago

saavedra29 commented 4 years ago

Description of the problem

When i try to get threads by name using the Client's search_for_threads method it hangs on connecting to the socket for ever

Code to reproduce

import atexit
import json
import getpass
import fbchat as fb

def load_cookies(filename):
    try:
        # Load cookies from file
        with open(filename) as f:
            return json.load(f)
    except FileNotFoundError:
        return  # No cookies yet

def save_cookies(filename, cookies):
    with open(filename, 'w') as f:
        json.dump(cookies, f)

def load_session(cookies):
    if not cookies:
        return
    try:
        return fb.Session.from_cookies(cookies)
    except fb.FacebookError:
        return  # Failed loading from cookies

cookies = load_cookies('session.json')
session = load_session(cookies)
if not session:
    # Session could not be loaded, login instead!
    session = fb.Session.login('myemail.com', getpass.getpass())

client = fb.Client(session=session)
threads = list(client.search_for_threads('the_group_to_search', limit=5))

Traceback

When i interrupt with the keyboard after a minute of waiting the last lines i get are

~/.virtualenvs/fbchat/lib/python3.8/site-packages/urllib3/util/connection.py in create_connection(address, timeout, source_address, socket_options)
     72             if source_address:
     73                 sock.bind(source_address)
---> 74             sock.connect(sa)
     75             return sock
     76 

Environment information

madsmtm commented 4 years ago

Thanks for the report. This is probably related to https://github.com/carpedm20/fbchat/issues/573, so I'll track our progress in that issue