AnswerDotAI / AnswerDotAI/ghapi
Starting example results in 404, should specify JWT to make it work
- Vorherrschende Sprache
- Python
- Sterne
- 685
- Forks
- 70
- Ø Merge
- 1 Min.
- Gemergte PRs (30 T.)
- 2
Beschreibung
The simple example results in a 404 error:
```python
api = GhApi(owner='owner', repo='repo', token='')
pulls = api.pulls.list()
```
but with curl it works (from GitHub docs):
```sh
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer " \
https://api.github.com/repos/OWNER/REPO/pulls
```
The following works:
```python
api = GhApi(owner='owner', repo='repo', jwt_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 ` but the example on GitHub specifies `Authorization: Bearer `. 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 ` 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 ...
Beitragsleitfaden
Rechercherichtung
Beginne damit, das einfache GhApi-Beispiel mit token='' nachzustellen und es mit jwt_token='' sowie der GitHub-curl-Anfrage zu vergleichen. Verfolge, wie GhApi den Authorization-Header erstellt, und aktualisiere anschließend das Einstiegsbeispiel oder dessen Authentifizierungshinweise, sodass api.pulls.list() nicht mehr den gemeldeten 404 erzeugt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- github, python
- Bereich
- api, authentication
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100