robertoszek / pleroma-bot

Bot for mirroring one or multiple Twitter accounts in Pleroma/Mastodon/Misskey.
https://robertoszek.github.io/pleroma-bot
MIT License
104 stars 18 forks source link

RSS Import: Issue with KeyError: 'cw' #126

Open AyotoCorp opened 1 year ago

AyotoCorp commented 1 year ago

Having a small issue where the bot will collect tweets while using RSS, but will fail to post because of the following error:

✖ 2023-03-19 13:45:58,341 - pleroma_bot - ERROR - Exception occurred for user, skipping... (cli.py:717) Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/pleroma_bot/cli.py", line 695, in main cw=tweet["cw"] KeyError: 'cw'

Commenting out that section lets it post a few times, but then it stops because of a number of other issues in a series of other lines which I didn't want to mess around with in case it broke further.

robertoszek commented 1 year ago

Hi! Which version of the bot do you have currently installed? You can check by running:

pleroma-bot --version

The latest release candidate as of now for the bot is v1.2.1rc20, which you can install like so:

pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple pleroma-bot==1.2.1rc20

I'm wondering if it still happening on v1.2.1rc20, I made some changes that haven't being merged into the stable version yet about populating cw for RSS feeds.

AyotoCorp commented 1 year ago

That was on 1.2.0. When I updated it, I got a different error instead during the posting part:

✖ 2023-03-19 23:30:54,211 - pleroma_bot - ERROR - Exception occurred for user, skipping... (cli.py:721) 
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/pleroma_bot/cli.py", line 688, in main
    post_id = user.post(
  File "/usr/local/lib/python3.10/dist-packages/pleroma_bot/_utils.py", line 796, in post
    post_id = self.post_pleroma(tweet, poll, sensitive, media, cw=cw)
  File "/usr/local/lib/python3.10/dist-packages/pleroma_bot/_pleroma.py", line 231, in post_pleroma
    item = media[key][0]
KeyError: '46vkwzdn9pc8socim97'

Which was very similar to the error I got when I commented out the cw line in the previous version.

robertoszek commented 1 year ago

Does it make any difference if you clean up the temp folder tweets generated at the path where your config.yml file is? Do you get the same exact error? Perhaps there's some orphan files from a previous failed run.

AyotoCorp commented 1 year ago

It looks like clearing out the tweets folder fixed it, I guess running it previously caused something to get stuck in the tweets that shouldn't have been there. Now I just have an issue where it's not pulling old tweets that were made when the bot wasn't functioning properly and posting them, but that's a separate issue.

nemobis commented 1 year ago

This happens because some fields are called even if they can be undefined. It could be fixed by making sure those fields are always initialised or by checking before reference. (Small example patch incoming.)