Python API שלח פוסטים

סיכום מבוסס בינה מלאכותית

In a Dev category discussion titled “Python API Send posts” tagged with rest-api, FunnySmile shares a Python solution for posting to Discourse using the fluent-discourse package, which simplifies API requests. They provide a code snippet demonstrating how to create a post with fields like title, raw content, category, and tags, and mention the ability to reply to existing topics by including a topic_id. FunnySmile promises to later explain how to retrieve category and post IDs. valsha requests an example, to which FunnySmile responds with an error message (“Uncaught (in promise) no-response”), possibly indicating a technical issue. FunnySmile apologizes for not being able to write more examples due to being busy. Finally, mapengfei-nwpu confirms the solution works and thanks the author. The original poster acknowledges possible language errors, as English is not their first language. The tool referenced is available at tools, and full API documentation can be found at https://docs.discourse.org/#operation/listPosts.

If you need to use Python to post to your forum, I’m sure this code will definitely help.

First of all, please get the tool post, tools.

Or get the package directly:

pip install fluent-discourse

For more interfaces, see:

Discourse API Docs

Thank you very much for simplifying the amount of code in the Python request API.

from fluent_discourse import Discourse
client = Discourse(base_url="url", username="user_name",
                   api_key="user_key", raise_for_rate_limit=True)
data = {
    'title': '',
# content
    'raw': '',
# Get a post ID when you need to reply to a post
#     'topic_id': '5',
# Category ID
   'category': '5',
# tags
    'tags': ['Label 1', 'Label 2'],

}
latest = client.posts.json.post(data)

You can use the API to reply or post a new topic if you only need to change what you need.
I’m sorry that there may be some mistakes in the description of this article, because English is not my mother tongue. Thank you for your understanding.

I’ll show you how to get the category ID and post ID later.

Can you post an example :slight_smile: Thank you.

Uncaught (in promise) no-response: no-response

I’m sorry that I’ve been too busy to write any more useful Python examples

I tried it and it works. Thank you very much!