Python request to forum keeps getting 401 error

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?

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)

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

3 Likes

That worked, thanks!

1 Like

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