# Python request to forum keeps getting 401 error

**URL:** https://meta.discourse.org/t/python-request-to-forum-keeps-getting-401-error/334899
**Category:** Development
**Created:** [November 7, 2024, 7:23am UTC](https://meta.discourse.org/t/python-request-to-forum-keeps-getting-401-error/334899 "2024-11-07T07:23:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [November 7, 2024, 7:23am UTC](https://meta.discourse.org/t/python-request-to-forum-keeps-getting-401-error/334899/1 "2024-11-07T07:23:29Z")

</div>

When I try to make a Python request to my own dev forum, I get a status code of `401`. My credentials are all correct (I think), so why should this happen?

```py
import requests

url = "https://bookish-garbanzo-x5wxpxv7xp96396wp-4200.app.github.dev/posts.json"

# Headers for the request
headers = {
    "Api-Key": " ************************************************************",
    "Api-Username": "NateDhaliwal",
    "Content-Type": "application/json"
}
# Form data to be sent in the request
payload = {
    "title": "This topic was made using the API",
    "raw": "Hello there, this **topic** was made using the API!",
    "category": 6
}
# Make the POST request with headers and form data
response = requests.post(url, headers=headers, json=payload)

# Print response status and text
print("Status Code:", response.status_code)

print("Response Body:", response.text)

```

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [November 7, 2024, 10:41am UTC](https://meta.discourse.org/t/python-request-to-forum-keeps-getting-401-error/334899/2 "2024-11-07T10:41:19Z")

</div>

> [@NateDhaliwal](#):
>
> `https://bookish-garbanzo-x5wxpxv7xp96396wp-4200.app.github.dev`

Are you running in github codespaces? If you want to access this domain outside an authenticated browser, you’ll need to make them public. More info here: [Security in GitHub Codespaces - GitHub Docs](https://docs.github.com/en/codespaces/reference/security-in-github-codespaces#port-forwarding)

---

<div class="post-metadata">

### Author: ![NateDhaliwal](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/natedhaliwal/32/313494_2.png) [@NateDhaliwal](https://meta.discourse.org/u/NateDhaliwal)
#### Post date: [November 7, 2024, 10:58am UTC](https://meta.discourse.org/t/python-request-to-forum-keeps-getting-401-error/334899/3 "2024-11-07T10:58:13Z")

</div>

That worked, thanks!

---

<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: [December 7, 2024, 10:58am UTC](https://meta.discourse.org/t/python-request-to-forum-keeps-getting-401-error/334899/4 "2024-12-07T10:58:22Z")

</div>

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