제 개발 포럼에 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)