AnswerDotAI / AnswerDotAI/ghapi
Starting example results in 404, should specify JWT to make it work
- Lenguaje dominante
- Python
- Estrellas
- 686
- Forks
- 69
- Merge medio
- 1 min
- PR fusionados (30 d)
- 2
Descripción
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 ...
Guía de contribución
Línea de trabajo
Comienza reproduciendo el ejemplo sencillo de GhApi con token='' y compáralo con jwt_token='' y la solicitud curl de GitHub. Rastrea cómo GhApi construye el encabezado Authorization y, después, actualiza el ejemplo inicial o sus indicaciones de autenticación para que api.pulls.list() ya no produzca el 404 reportado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- github, python
- Área
- api, authentication
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100