Starting example results in 404, should specify JWT to make it work
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- github, python
- Lĩnh vực
- api, authentication
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ GhApi đơn giản với token='' và so sánh nó với jwt_token='' cũng như yêu cầu curl của GitHub. Theo dõi cách GhApi xây dựng header Authorization, sau đó cập nhật ví dụ ban đầu hoặc hướng dẫn xác thực của ví dụ đó để api.pulls.list() không còn tạo ra lỗi 404 đã báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The simple example results in a 404 error:
api = GhApi(owner='owner', repo='repo', token='<YOUR-TOKEN>')
pulls = api.pulls.list()
but with curl it works (from GitHub docs):
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
https://api.github.com/repos/OWNER/REPO/pulls
The following works:
api = GhApi(owner='owner', repo='repo', jwt_token='<YOUR-TOKEN>')
pulls = api.pulls.list()
The personal access token has scopes for repo, workflow, gist and notifications.
Cause
It seems the API call to GitHub expects a different header. The example on GhApi sets Authorization: token <YOUR-TOKEN> but the example on GitHub specifies Authorization: Bearer <YOUR-TOKEN>. On https://docs.github.com/en/rest/overview/other-authentication-methods this is expanded upon with the note:
Note: In most cases, you can use Authorization: Bearer or Authorization: token to pass a token. However, if you are passing a JSON web token (JWT), you must use Authorization: Bearer.
Reading the docs I assume the header Authorization: token <TOKEN> is fine, but the above experimentation indicates otherwise.
Conclusion
I have no clue why 'my' token is regarded as a JWT token here, and in the example of GhApi not. For me it works, but I couldn't find a reason. Perhaps it helps someone searching for this, but I'm also interested to known if it is a setting or ...
- Ngôn ngữ chính
- Python
- Star
- 687
- Fork
- 69
- Merge trung bình
- 1 phút
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của AnswerDotAI/ghapi
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
AnswerDotAI/ghapi#158 ·
-
Small fix needed to enable GHES Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
AnswerDotAI/ghapi#120 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 58/100
AnswerDotAI/ghapi#208 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
AnswerDotAI/ghapi#201 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
AnswerDotAI/ghapi#186 ·
Tất cả issue của AnswerDotAI/ghapi
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
stephrobert/dsoxlab#238 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
sublimehq/package_control#1780 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
nwg-piotr/nwg-displays#145 ·