Hi,

Not sure if its ok to ask questions in here…?

I’m very much a beginner at python but I’ve managed to get my python script set up to post to a community. The only issue is that I can only post to communities on my own instance.

I feel like I’m missing something obvious related to community_id or community_name.

from pythorhead import Lemmy

lemmy = Lemmy('https://lemmy.fmhy.ml')
lemmy.log_in('username', 'password')
community_id = lemmy.discover_community('test_video_bot')
lemmy.post.create(community_id, url='https://www.youtube.com/watch?v=riuGVkq2DKw', name='Football Highlights')

Above is my current code which works but if I remove the ‘test_video_bot’ community on my instance and replace it with ‘lemmy.world/c/football’ or ‘lemmy.fmhy.ml/c/football@lemmy.world’ I get two errors:


Error encountered while Request.GET: {"error":"couldnt_find_community"}
Error encountered while Request.POST: Json deserialize error: invalid type: null, expected i32 at line 1 column 21

It’s as if it’s only searching my own instance and I’m not sure how to tell it to look elsewhere or if it’s not possible yet to do this on pythorhead.

Thanks for any suggestions you can give to help with this issue.

You are viewing a single thread.
View all comments
5 points

Hey, you can do it by using this notation:

community_id = lemmy.discover_community('firefox@lemmy.ml')

If it helps, this is what you see in the URL when you visit a non-local community.

permalink
report
reply
2 points

Op here on different account.

Thanks. Will give this a go.

permalink
report
parent
reply

Pythörhead

!pythorhead@lemmy.dbzer0.com

Create post

A community to post announcements, updates, integrations and even memes about the first & best Lemmy Python Library

Community stats

  • 6

    Monthly active users

  • 42

    Posts

  • 11

    Comments

Community moderators