question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FBchatException: Could not fetch thread 2355367: {u'message_thread': None}

See original GitHub issue

Description of the problem

FBchatException: Could not fetch thread 2355367: {u’message_thread’: None} - It has something to do with the line thread_id=client.uid

Code to reproduce

# Example code
from fbchat import  Client, log
from fbchat.models import *
import fileinput

class punkjj(Client):

    def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs):
        toggle = client.fetchThreadMessages(thread_id=client.uid, limit=1) # client.uid means its our own acc
        for message in toggle:
            pText=message.text.lower()
        if("online" in pText):
            self.markAsRead(author_id)
        log.info("Message {} from {} in {}".format(message_object, thread_id, thread_type))  
        msgText = message_object.text.lower()
        if(msgText=="hi" or msgText=="hii" or msgText=="hiii" or msgText=="yo" or msgText=="hi there" or msgText=="hey" or msgText=="heyy"):
            reply = "Hello :D"
        elif(msgText=="hello" or msgText=="hellow" or msgText=="heloo" or msgText=="hlo" or msgText=="hellow"):
            reply = "Hi :)"
        elif(msgText=="hy" or msgText=="hyy"):
            reply = "Hello :D"
        elif(msgText=="whatsup" or msgText=="wassup" or msgText=="what's up" or msgText=="wtsup" or msgText=="watsup" or msgText=="whats up" or "how are you" in msgText or "hw r u" in msgText):
            reply = "Awesome. What about you? :D"
        elif(msgText=="test" or msgText=="debug" or msgText=="aboutme" or msgText=="about" or msgText=="bot"):
            reply = "Hi, I'm a bot written in Python. Created by Pankaj Sheoran"
        elif("birthday" in msgText or "bday" in msgText or "hbd" in msgText):
            reply = "Thank you! :D"
        elif("what you doing" in msgText):
            reply = "Idling, I'm a bot afterall. I work for my creator, Pankaj Sheoran (www.punkjj.cf)"
        elif("bye" in msgText or msgText=="byye" or msgText=="byee"):
            reply = "Ok bye! :D"
        else:
            reply = "Thank you for contacting me. I'm currently not online, I was replying using a Python Script. I will reach out to you shortly."
        def sendMsgg():
            if (author_id!=self.uid):
                self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type)
            self.markAsDelivered(author_id, thread_id)     
        if ("online" in pText):
            sendMsgg()

client = punkjj("EMAIL", "PASSWORD")

client.listen()

Traceback

Traceback (most recent call last):
  File "/Users/username/Library/Python/2.7/lib/python/site-packages/fbchat/client.py", line 2278, in _parseMessage
    thread_id=thread_id, thread_type=thread_type, ts=ts, metadata=metadata, msg=m)
  File "test.py", line 10, in onMessage
    toggle = client.fetchThreadMessages(thread_id=client.uid, limit=1) # client.uid means its our own acc
  File "/Users/username/Library/Python/2.7/lib/python/site-packages/fbchat/client.py", line 845, in fetchThreadMessages
    raise FBchatException('Could not fetch thread {}: {}'.format(thread_id, j))
FBchatException: Could not fetch thread 2355367: {u'message_thread': None}

Environment information

  • Python 2.7
  • fbchat (1.4.2)
  • If relevant, output from $ python -m pip list

If you have done any research, include that. Make sure to redact all personal information.

I’ve search google, but I’m fairly new this API and there wasn’t any examples of “auto-reply” except for one script I found on the web called FB-AutoReply. That’s all I know. Please help. I believe it has something to do with the “client.uid” in which it’s adding my Profile ID, and I don’t understand why it needs that. Has this script worked for anyone else?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mattyicercommented, Jan 25, 2019

wait…so I do this:

if author_id != self.uid:
            Client.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type)

Nope…that didn’t work. Ah, please bare with me 😃

I think I’m confuse as to where I put Client.send into the script…

UPDATE Got it to work. Thanks so much for your help. Such a nice fella. 👍

0reactions
mattyicercommented, Jan 25, 2019

No sir, we’re all good. You’re the man! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Source code for fbchat._client
INFO`` Raises: FBchatException: On failed login """ self. ... before=None, after=None, limit=None): """Fetch all threads in ``thread_location``.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found