fbchat icon indicating copy to clipboard operation
fbchat copied to clipboard

Error when getting jsmods_require on sent message

Open szymonszl opened this issue 5 years ago • 10 comments

Description of the problem

When a message is sent, a very long error can be seen in the console. No traceback is seen. The message is delivered.

Code to reproduce

#!/usr/bin/env python3
import fbchat
from fbchat import models

cookie_file = 'cookies.json'
with open(cookie_file, 'r') as fd:
    cookies = json.load(fd)

client = fbchat.Client(email, password, session_cookies=cookies)

with open(cookie_file, 'w') as fd:
    cookies = client.getSession()
    json.dump(cookies, fd)

client.send(models.Message(text="test"), thread_id=owner) # owner = my UID

Traceback

The error message is very long, to save you scrolling I've pastebinned it: https://pastebin.com/g5y46quv

Environment information

  • Python version: Python 3.7.3
  • fbchat version: 1.7.2

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

szymonszl avatar Jul 11 '19 20:07 szymonszl

The error is in this case mostly just a warning, you should be able to safely ignore it, but still, thanks for the report, the data you've provided will be very useful in the future for figuring out how the jsmods result works!

madsmtm avatar Jul 20 '19 14:07 madsmtm

access python3 dist-packages edit _client.py as root change line 1171 to be like this fb_dtsg = None .. it might cause other problems i might upload a fork later

AlphaArslan avatar Aug 09 '19 16:08 AlphaArslan

@madsmtm

AlphaArslan avatar Aug 09 '19 16:08 AlphaArslan

Hi @AlphaArslan, thanks for the PR, but it might not be the best approach. There's a reason that the get_jsmods_require line is present, something about refreshing the fb_dtsg variable when needed, which I'm quite certain improves stability, though I don't recall the specifics - So on that basis, I'll close your PR 😉.

The better solution is to, well, figure out how the jsmods result works. Until now it has only seenseen a bit of sporadic work on my side, but I do intend to look into it further in the future.

madsmtm avatar Aug 22 '19 20:08 madsmtm

Hi there guys, i'm new to the forum and to Python.

I was working on a personal project of sending every x hours random images (from a folder on the laptop) to a certain facebook friend and got almost the same error message as @szymonszl did here : https://pastebin.com/g5y46quv

The code works, the random pictures are sent, but almost everytime i get the long error message "Error when getting jsmods_require: {'__ar': 1, 'payload': {'actions': [{'thread_id': '', 'thread_fbid ......"

The code is -

import fbchat
from fbchat.models import *
import random,os
from apscheduler.schedulers.blocking import BlockingScheduler


client = fbchat.Client("username", "password")
friend = client.searchForUsers("fb friend")
id = friend[0].uid
path = r"D:\Downloads"


def mesaj_fb():

  random_filename = random.choice([
  x for x in os.listdir(path)
  if os.path.isfile(os.path.join(path, x))])

  print(random_filename)
  client.sendLocalImage(os.path.join(path, random_filename),message=Message(text="your daily pic..."),thread_id=id)


sched = BlockingScheduler()
sched.add_job(mesaj_fb, 'interval', minutes=1)
sched.start()

I don't know why, but i cannot insert the above text as a code on the forum. Sorry Do you have any ideea how i could fix this? Thanks.

piecharm9 avatar Dec 30 '19 22:12 piecharm9

Thanks for the report, @piecharm9. I edited your message to fix the code embedding (you have to use ``` around the code segment).

Regarding your error, just ignore it, it's because Facebook changed something, that we've yet to properly identify how works. Your code should work just fine without it!

madsmtm avatar Jan 01 '20 21:01 madsmtm

You're welcome @madsmtm . I think i have found the solution to the error. It's all about the frequency of the messages. If the code sends a message every 1 minute, the error appears. If it send a message every 30 minutes, no more error!!

So i think maybe it's a spam protection from facebook.

piecharm9 avatar Jan 01 '20 21:01 piecharm9

It is due to sending message repetitively , you might want to logout / kill the session and relogin after every 3-4 messages ( or until what ever number of times it threw the error ) which should solve the problem

srinivasbusy avatar Apr 04 '20 18:04 srinivasbusy

The issue seems to be present even when sending a single message and logging out afterwards. Is there a way to ignore it?

yungsinatra0 avatar May 10 '20 14:05 yungsinatra0

I am having this same issue and can confirm that for me it is occurring on the first, and subsequent messages I send, despite logging in and out.

bradc87 avatar Sep 20 '20 03:09 bradc87