Q: Which headers should I provide for authentication in GitHub API? I'm trying to use Basic Authentication in GitHub API. I wrote something like this:
reqURL = "https://api.github.com/repos/user/repo"
pullreqsURL = urllib.request.Request(reqURL)
pullreqsURL.add_header("Authorization", "Basic " + str(base64.urlsafe_b64encode(b'Username:myAuthTokenORpass')) )
pullreqsURL.add_header("Content-Type", "application/json")
pullreqsURL.add_header("Accept", "application/json")
urllib.request.urlopen(pullreqsURL)

However, it keeps throwing HTTPError.
With commented 3rd line it goes well.
Well. I've solved it using personal token instead of user:pass
pullreqsURL.add_header("Authorization", "token >mytoken<" )


A: It should be possible to authenticate via Basic Authentication with username/password.
Quote from the link:

Via Username and Password
To use Basic Authentication with the GitHub API, simply send the
  username and password associated with the account.

However, I don't know Python, so I don't know whether str(base64.urlsafe_b64encode(b'Username:myAuthTokenORpass')) is the proper way to Base64 encode username/password.
As you mentioned personal access tokens, it's also possible to authenticate via Basic Authentication, but with an access token instead of your real password.
This is explained in my first link as well.
Quote:

Via OAuth Tokens
Alternatively, you can use personal access
  tokens or OAuth
  tokens instead of your password.
curl -u username:token https://api.github.com/user

This approach is useful if your tools only support Basic
  Authentication but you want to take advantage of OAuth access token
  security features.

I'm using this approach with success in a project of mine.
