# Publishing a post with API and Python doesn't work

**URL:** <https://forum.ghost.org/t/publishing-a-post-with-api-and-python-doesnt-work/39497>\
**Category:** Developer help\
**Created:** [June 27, 2023, 7:44pm UTC](https://forum.ghost.org/t/publishing-a-post-with-api-and-python-doesnt-work/39497 "2023-06-27T19:44:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![giacomosilli](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/giacomosilli/32/3403_2.png) [@giacomosilli](https://forum.ghost.org/u/giacomosilli)\
**Post date:** [June 27, 2023, 7:44pm UTC](https://forum.ghost.org/t/publishing-a-post-with-api-and-python-doesnt-work/39497/1 "2023-06-27T19:44:18Z")

</div>

if I use nodejs like this, the article publishes correctly:

```auto
payload = {
    posts: [{
        title: "My test post",
        html: "<p>My post content. Work in progress...</p>",
        status: "published"
    }]
};
response = await axios.post(urlInsert, payload, { headers })

```

if I use python it doesn’t work, the post isn’t even written:

```auto
post_data = {
    "posts": [{
        "title": "My test post",
        "html": "<p>My post content. Work in progress...</p>",
        "status": "published"
    }]
}
response = requests.post(url, headers = headers, json = post_data)

```

if instead I use draft the post is written, but obviously it is not published with python:

```auto
post_data = {
    "posts": [{
        "title": "My test post",
        "html": "<p>My post content. Work in progress...</p>",
        "status": "draft"
    }]
}
response = requests.post(url, headers = headers, json = post_data)

```

---

<div class="post-metadata">

**Author:** ![Cathy\_Sarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/cathy_sarisky/32/25750_2.png) [@Cathy\_Sarisky](https://forum.ghost.org/u/Cathy_Sarisky)\
**Post date:** [June 27, 2023, 8:11pm UTC](https://forum.ghost.org/t/publishing-a-post-with-api-and-python-doesnt-work/39497/2 "2023-06-27T20:11:10Z")

</div>

Are you authenticating in the same way, with the same key or jwt? This behavior might be consistent with a permissions error if you’re using a contributor key…

---

<div class="post-metadata">

**Author:** ![giacomosilli](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/giacomosilli/32/3403_2.png) [@giacomosilli](https://forum.ghost.org/u/giacomosilli)\
**Post date:** [June 27, 2023, 10:51pm UTC](https://forum.ghost.org/t/publishing-a-post-with-api-and-python-doesnt-work/39497/3 "2023-06-27T22:51:41Z")

</div>

The **Admin Key** is the same, and this is the code:

nodejs:

```auto
token = jwt.sign({}, Buffer.from(secret, 'hex'), {
            keyid: id,
            algorithm: 'HS256',
            expiresIn: '5m',
            audience: `/v3/admin/`
        });
headers = { Authorization: `Ghost ${token}` };

```

python:

```auto
payload = {
    'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=5),
    'iat': datetime.datetime.utcnow(),
    'aud': '/v3/admin/'
}

token = jwt.encode(payload, bytes.fromhex(secret), algorithm='HS256', headers={'kid': id})
headers = { 'Authorization': f"Ghost {token}" }

```

---

<div class="post-metadata">

**Author:** ![Cathy\_Sarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/cathy_sarisky/32/25750_2.png) [@Cathy\_Sarisky](https://forum.ghost.org/u/Cathy_Sarisky)\
**Post date:** [June 28, 2023, 3:13am UTC](https://forum.ghost.org/t/publishing-a-post-with-api-and-python-doesnt-work/39497/4 "2023-06-28T03:13:44Z")

</div>

How weird. Do you have access to logging from the Ghost site that might help with the diagnosis?

---

<div class="post-metadata">

**Author:** ![giacomosilli](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/giacomosilli/32/3403_2.png) [@giacomosilli](https://forum.ghost.org/u/giacomosilli)\
**Post date:** [June 28, 2023, 12:57pm UTC](https://forum.ghost.org/t/publishing-a-post-with-api-and-python-doesnt-work/39497/5 "2023-06-28T12:57:30Z")

</div>

I understood the problem, it wasn’t something related to the language used, I had a trigger on post.published that created problems.

Thanks for your help
