Pythonでフォーラムへのリクエストが401エラーを繰り返す

自分の開発者フォーラムにPythonリクエストを送信しようとすると、ステータスコード 401 が返されます。認証情報はすべて正しい(と思っている)のですが、なぜこのようなことが起こるのでしょうか?

import requests

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

# リクエストのヘッダー
headers = {
    "Api-Key": "************************************************************",
    "Api-Username": "NateDhaliwal",
    "Content-Type": "application/json"
}
# リクエストで送信されるフォームデータ
payload = {
    "title": "This topic was made using the API",
    "raw": "Hello there, this **topic** was made using the API!",
    "category": 6
}
# ヘッダーとフォームデータを使用してPOSTリクエストを実行
response = requests.post(url, headers=headers, json=payload)

# レスポンスのステータスとテキストを出力
print("Status Code:", response.status_code)

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

GitHub Codespaces で実行していますか?認証済みブラウザー以外でこのドメインにアクセスしたい場合は、パブリックにする必要があります。詳細はこちら: Security in GitHub Codespaces - GitHub Docs

「いいね!」 3

うまくいきました、ありがとう!

「いいね!」 1

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