# Failed to post a topic

**URL:** https://meta.discourse.org/t/failed-to-post-a-topic/282471
**Category:** Development
**Tags:** rest-api
**Created:** [October 17, 2023, 1:06am UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471 "2023-10-17T01:06:36Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 17, 2023, 1:06am UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/1 "2023-10-17T01:06:36Z")

</div>

tried to post a topic with the API, it failed with this error msg:  
_{‘action’: ‘create\_post’, ‘errors’: [‘Body is too short (minimum is 1 character)’, ‘Body seems unclear, is it a complete sentence?’]}_

- the message to post is around 25K, a list of news  
can post it manually without error.  
but when post it with API, it fails  
the default post size is 35K(?), already increase it (in settings) to allow this longer message.
- if post a short sentence with the code below, it works fine.

changed `body min entropy` to 0, it did not help either.

searched the forum, not found a solution,  
any idea/suggestions, thanks…

here is the python code

```plaintext
import requests

# Authentication headers
headers = {
    "Api-Key": '***',
    "Api-Username": 'newsbot',
}

lines = "some news, around 25K"

# Topic data
topic_data = {
    "title":"latest news",
    "raw": lines,
    "category": 28,  
}

# Send a POST request to create the topic
response = requests.post('https://www.mydomain.com/posts.json', json=topic_data, headers=headers)

# Check if the request was successful
if response.status_code == 200:
    print("Topic created successfully!")
    topic_id = response.json().get("id")
    print(f"Topic ID: {topic_id}")
else:
    print(response.json())
    print(f"Failed to create the topic. Status code: {response.status_code}")

```

btw, the content to post is a list of news like this

```plaintext
[grid]
![](https://static01.nyt.com/images/2023/10/16/multimedia/animage.jpg)
![](https://content.api.news/v3/images/bin/image.jpg)
[/grid]

<details><summary><b>news title</b></summary>
news conentnews conentnews conentnews conentnews 
conent news conentnews conentnews conentnews conentnews 
conentnews conentnews conentnews conentnews conentnews 
conentnews conentnews conentnews conentnews conent
about this long for one news

[The New source 2023-10-16T21:16:45Z](https://www.newssource.com/live/anews)

```

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 17, 2023, 1:39am UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/2 "2023-10-17T01:39:29Z")

</div>

> [@fbpbdmin](#):
>
> {‘action’: ‘create\_post’, ‘errors’: [‘Body is too short (minimum is 1 character)’, ‘Body seems unclear, is it a complete sentence?’]}

Try adding `"skip_validations": true` to the `topic_data`. (There are cases where `true` needs to be enclosed in quotation marks, but I don’t think that’s the case with Python.)

The `skip_validations` parameter will get Discourse to skip performing the validations against site settings like `min topic title length` and `body min entropy`.

---

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 17, 2023, 11:31am UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/3 "2023-10-17T11:31:46Z")

</div>

thanks @simon

tried

```plaintext
"skip_validations": True

```

it suppressed the error, created a topic, but it is empty, hmm…  
suspect maybe the html syntax in my post content needs to be coded ?

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [October 17, 2023, 11:39am UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/4 "2023-10-17T11:39:21Z")

</div>

Random guess… Maybe set the `Content-Type` as `application/json`?

---

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 17, 2023, 12:03pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/5 "2023-10-17T12:03:47Z")

</div>

> [@Canapin](#):
>
> `Content-Type` as `application/json`

tried in header or body (topic\_data) , it still create a new empty topic post.

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [October 17, 2023, 12:22pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/6 "2023-10-17T12:22:01Z")

</div>

I tried your python script (without specifying the content-type) on my instance and it worked perfectly:

 ![image](https://global.discourse-cdn.com/meta/original/4X/1/b/0/1b0ede77b00bed85f17ec60626a20f5cfc374dbe.png)

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [October 17, 2023, 12:23pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/7 "2023-10-17T12:23:00Z")

</div>

I have to ask it, but does your code work with a short text? Did you check that you actually pass non-empty content in the API?

---

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 17, 2023, 1:52pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/8 "2023-10-17T13:52:22Z")

</div>

yes, it works for short content, but not the long one (attached), 29848 chars, not due to the length,  
suspected maybe some special character ?

thanks for your help !  
[test.zip](https://meta.discourse.org/uploads/short-url/hEArytELUeDcua5Sxt55ZJZnx57.zip) (12.1 KB)

---

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 17, 2023, 1:53pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/9 "2023-10-17T13:53:42Z")

</div>

thanks @Arkshine  
yes, mentioned in the posts above…

---

<div class="post-metadata">

### Author: ![Canapin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/canapin/32/119591_2.png) [@Canapin](https://meta.discourse.org/u/Canapin)
#### Post date: [October 17, 2023, 2:05pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/10 "2023-10-17T14:05:38Z")

</div>

I tried with your text and it works:

 ![image](https://global.discourse-cdn.com/meta/original/4X/9/a/7/9a7be2bdf0871b2f4e31e6a5e3e9f19933479d1e.jpeg)

Did you enclose your string with triple quotes (either `'''` or `"""`) to avoid escaping issues?

How do you load your post’s content in your python script (I suppose you take your content from an external source)?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [October 17, 2023, 2:19pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/11 "2023-10-17T14:19:29Z")

</div>

Same on my side; I have no issue with your content. I guess there is something wrong with how you retrieve/load the data. 🤔

---

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 17, 2023, 3:43pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/12 "2023-10-17T15:43:14Z")

</div>

hmm… thanks for trying… interesting…  
I loaded the news content from a file like this…

```plaintext
with open(sys.argv[1]) as f:
    lines = [line for line in f]
 
print(lines)
print(len(lines))

```

it got the file content correctly, hmm…

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [October 17, 2023, 4:23pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/13 "2023-10-17T16:23:24Z")

</div>

Did you try passing `encoding="utf8"` in `open()`? That might help.

---

<div class="post-metadata">

### Author: ![fbpbdmin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fbpbdmin/32/300893_2.png) [@fbpbdmin](https://meta.discourse.org/u/fbpbdmin)
#### Post date: [October 18, 2023, 7:28pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/14 "2023-10-18T19:28:02Z")

</div>

yes, something not right with loading the file content…  
thanks… false alarm… 🙂

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [November 17, 2023, 7:28pm UTC](https://meta.discourse.org/t/failed-to-post-a-topic/282471/15 "2023-11-17T19:28:54Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
