GithubHelp home page GithubHelp logo

Comments (7)

mtthwnestor avatar mtthwnestor commented on June 18, 2024

My personal Lemmy instance is running 0.18.0, and lemmy-bot has no problem logging in. However, I'm seeing the FetchError: invalid json response body error when trying to create a post. Is this possibly related, or am I just doing something wrong?

Starting bot
Initializing DB
logging in
logged in
Marking account as bot account
user_already_exists
Creating post

/app/node_modules/node-fetch/lib/index.js:273
				return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));
				                           ^
FetchError: invalid json response body at https://lemmy.mydomain.net/api/v3/post reason: Unexpected token 'J', "Json deser"... is not valid JSON
    at /app/node_modules/node-fetch/lib/index.js:273:32
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'invalid-json'
}

from lemmy-bot.

SleeplessOne1917 avatar SleeplessOne1917 commented on June 18, 2024

I'm trying to figure out if this is a problem with the bot library, the js client library, or the server-side of the API. I'm seen similar errors of invalid JSON bodies pop up in error toasts on the UI project sometimes.

from lemmy-bot.

mtthwnestor avatar mtthwnestor commented on June 18, 2024

The error messages seem to be coming this way because Lemmy API returns plain text instead of JSON. This issue just got closed, so hopefully, the errors will be handled in a more useful way in the next release: LemmyNet/lemmy#3366

However, I still don't know what is triggering the error for me in the first place. I am not that good with Typescript yet, so I am probably doing something wrong, but getting a more reasonable error message should help me as I try to figure it out.

from lemmy-bot.

nebbishOne avatar nebbishOne commented on June 18, 2024

I am getting this error as well. I have lemmy-bot 0.4.5, node 18.16.1, npm 9.5.1.

I am just learning node, etc... really. I just created a new project, a new index.js in that folder and then copied in the Congratulator bot example, since that's close to what I want to do. I did 'npm init' and 'npm install'. I edited the credentials, and the comment text in the JS file. I run it as 'node index.js' from the terminal and getting the Invalid JSON message above.

Starting bot
Creating database file
Initializing DB
logging in
logged in
Marking account as bot account
user_already_exists

/app/node_modules/node-fetch/lib/index.js:273
				return Body.Promise.reject(new FetchError(`invalid json response body at ${_this2.url} reason: ${err.message}`, 'invalid-json'));

Node.js v18.16.1

Is there anything I can edit on my PC to get this working? Or do we need to wait for the next Lemmy release? Thanks for any pointers.

EDIT TO ADD: Thanks to sylverstream, I added the same console.log() and got this:

Json deserialize error: missing field `post_id` at line 1 column 198

EDIT TO ADD AGAIN: I found a defect in my bot script. It was passing in "postId" but should have passed "post_id". With that fixed, my bot is working! @sylverstream - check your code for a similar mistake, maybe. I think the bot library itself is OK, in other words.

from lemmy-bot.

sylverstream avatar sylverstream commented on June 18, 2024

I've also got the same error. In my case, the logging in fails. I've added a console.log in node_modules/node-fetch/lib/index.js to see the Lemmy response.
I've added this code at line 273 (in the catch block):
console.log(buffer.toString());

In my case the error returned by Lemmy.world is: Json deserialize error: missing field username_or_email at line 1 column 1

@SleeplessOne1917 hopefully that helps?

from lemmy-bot.

etymotic avatar etymotic commented on June 18, 2024

The error messages seem to be coming this way because Lemmy API returns plain text instead of JSON. This issue just got closed, so hopefully, the errors will be handled in a more useful way in the next release: LemmyNet/lemmy#3366

However, I still don't know what is triggering the error for me in the first place. I am not that good with Typescript yet, so I am probably doing something wrong, but getting a more reasonable error message should help me as I try to figure it out.

I wonder, are we still waiting on an update to Lemmy before this is addressed?

For me this only happens when trying to pin a post using Lemmy-Frank-Bot.

from lemmy-bot.

SleeplessOne1917 avatar SleeplessOne1917 commented on June 18, 2024

I wonder, are we still waiting on an update to Lemmy before this is addressed?

Lemmy version 0.19.0 is going to release (hopefully) this week, so hopefully this will allow us to check whether this is an issue with the API or the bot.

from lemmy-bot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.