Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Starting example results in 404, should specify JWT to make it work

Đang mở
#147 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AnswerDotAI/ghapi

Tất cả issue của AnswerDotAI/ghapi

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.