거의 반복되는 문제인 것 같습니다. bash와 curl에서 API Github를 이런 식으로 호출합니다.
# curl -u myuser https://api.github.com/repos/myuser/somerepo/pulls?state=all -H "Authorization: token randomtokenhere" -d '{"title":"Pull Request develop to master","base":"master", "head":"develop"}'
그리고 매력처럼 작동합니다. 그러나 json 및 요청이있는 Python 3 (3.5.2)에서 무엇이든 오류가 발생했습니다.
예 :
user = "myuser"
password = "sompassword"
url = "https://api.github.com/repos/myuser/somerepo/pulls?state=all"
token = "randomtokenhere"
title = "Pull Request develop to master"
base = "master"
head = "develop"
headers = {'Authorization': 'token ' + token}
content = {"title":title,"base":base, "head":head}
req = requests.post(url,json=json.dumps(content),auth=(user,password),headers=headers)
print("response posts is {} and status code is {}".format(req.text,req.status_code))
요청의 응답은
response posts is {"message":"Must specify two-factor authentication OTP code.","documentation_url":"https://developer.github.com/v3/auth#working-with-two-factor-authentication"} and status code is 401
그래서 호출에 어떤 식 으로든 토큰이 누락 된 것 같습니다. 그러나 나는 이유를 알 수 없습니다. 어떤 식 으로든 디버깅 할 수 있습니까? 아니면 매우 분명한 것을 놓쳤습니까?
감사합니다
-
답변 # 1
관련 자료
- 요청을 사용하여 Python의 curl에서 API에서 데이터 가져 오기
- Python 요청을 사용할 때 잘못된 URL
- ssl - Python 요청 문제 SSLCertVerificationError
- python을 사용하여 파일 보내기 및 받기 - fastapi 및 요청
- authentication - python - 로그인 후 요청 실패
- azure python webapp에 대한 github 작업 - 게시 프로필에서 자격 증명을 가져 오지 못했습니다
- web scraping - Python 요청 모듈이 requestsget ()에서 멈추고 시간 초과 됨
- Python Requests SSL TLSV13_ALERT_CERTIFICATE_REQUIRED - python이 ssl을 요청합니다 tlsv13_alert_certificate_required - tlsv13 경고 인증서 필요
- r - github에서 다운로드하면 '404 찾을 수 없음'과 잘못된 다운로드 크기가 반환됩니다
- Authorization TOKEN을 Python 요청 헤더에 전달하는 방법
- Python Requests POST - python이 post를 요청합니다400 - python 요청이있는 잘못된 요청
- Python 코드 (discordpy)에 Github에서 가져온 폴더의 이름을 작성하는 방법은 무엇입니까?
- Python - 파이썬 - 요청으로 api에 patch 요청을하는 방법
- Python Webscrape 요청 대 셀레늄
- web scraping - 요청 Python에서 URL로 최대 재 시도를 초과했습니다
- curl - Python 요청으로 Flask 애플리케이션에 파일을 업로드하는 방법
- Python OS - python os - 'oslistdir'을 사용하여 폴더 목록을 반환하는 디렉터리를 봅니다 하위 폴더의 내용을 보려면 어떻게합니까?
글쎄요, 귀찮게해서 전화가 잘못되었습니다. 이것은 실제로 효과가있었습니다 :
json.dumps 함수를 제거하고 headers 매개 변수를 제거했으며 대신 암호를 사용하여 auth로 토큰을 설정했습니다.
안녕하세요