I been trying to generate a Token for self-hosted machines using the GitHub-API for my Org.
Using Curl it works as expected from GitHubs doc
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <MY-TOKEN>" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/<MY-ORG>/actions/runners/registration-token
response
{
"token": "RUNNER_TOKEN",
"expires_at": "2023-09-01T23:47:56.042+02:00"
}
Then I tried to re-create this is Python, using the requests lib
def get_runner_token(token, org):
url = f"https://api.github.com/orgs/{org}/actions/runners/registration-token"
authorization = f'Bearer {token}' # Tried both as Bearer and token
headers = CaseInsensitiveDict() # Tried as normal dict as well
headers['Accept'] = "application/vnd.github+json" # Tried removing accept and API version
headers['Authorization'] = authorization
headers['X-GitHub-Api-Version'] = "2022-11-28"
payload = {} #Tried with and without payload...
print("Sending request to", url, "with headers", headers)
x = requests.post(url, headers=headers, data=payload)
print(x, x.json())
No matter what I do I keep getting the response
<Response [401]> {'message': 'Bad credentials', 'documentation_url': 'https://docs.github.com/rest'}
If don't send the token as an arg through a function like so:
def get_runner_token(org):
token = "..."
# Same as code above....
It works? I don't understand Can anybody see what I might be doing wrong?
While very similar to Github API works in curl but not python - bad credentials. None of the answers worked for me
organdtokenfilled out with appropriate values).