I'm trying to add the authentication in the Http header and then do a http post, the target url is a Github API like this: https://api.github.com/user
, the code below always response 401, unauthorized, my question is, how to add the authentication in the header? Is the way I did correct?
username = raw_input('Github name: ')
token = raw_input('Access Token: ')
url = 'https://api.github.com/user'
values = {"Username":username,"Password":token}
data = urllib.urlencode(values)
req = urllib2.Request(url,data)
response = urllib2.urlopen(req)
the_page = response.read()