I took it a challenge from myself to sign in github without using the API but with using requests module.I managed to get to this code and I get 200 status code but still there is a message which is "Incorrect username or password." even if the credentials is right!
any help appreciated. Thanks.
import requests
from bs4 import BeautifulSoup
def github_login():
s = requests.Session()
git = BeautifulSoup(s.get('https://github.com/login').text, 'html.parser')
auth_token = git.find("input", {"name": "authenticity_token"}).attrs['value']
commit = git.find("input", {"name": "commit"}).attrs['value']
data = {
'username': 'username',
'password': 'password',
'commit' : commit,
'authenticity_token' : auth_token
}
headers = {
"Host": "www.github.com",
"Origin": "https://www.github.com",
"X-Requested-With": "XMLHttpRequest",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5",
}
login = s.post('https://github.com/session', data=data)
print (login.status_code)
print(login.text)
github_login()