p = 'userpass'
url = 'https://api.github.com/users/username'

def encodeUserData(user, password):
    return 'Basic ' + (user + ':' + password).encode('base64').rstrip()
req = urllib.request.Request(url)
req.add_header('Accept', 'application/json')
req.add_header('Content-type', 'application/x-www-form-urlencoded')
req.add_header('Authorization', encodeUserData(u, p))
res = urllib.request.urlopen(req)
print(res.read())
Альтернатива CURL в Python