I want to update a file with the Github API and commit it into a branch. I have troubles creating the commit. The SHA does not match the expected one.
{
'documentation_url': 'https://developer.github.com/enterprise/2.7/v3/repos/contents/',
'message': 'pom.xml does not match de42fdd980f9b8067a2af982de46b8d5547e4597'
}
I do the following:
import hashlib
myfile = "new content of my README"
resulting_file = base64.b64encode(bytes(myfile, "utf-8"))
file_as_str = str(resulting_file.decode('utf-8'))
sha = hashlib.sha1(file_as_str.encode('utf-8')).hexdigest()
url = 'https://someurl.com/someproject/contents/README.md?access_token=' + access_token
data = '{"message": "bla bla", "content": "'+file_as_str+'", "sha": "'+sha+'", "branch": "'+branch+'"}'
response = requests.put(url, data=data)
I would not like to use a lib to do this to better understand what is happening. probably the SHA is not generated properly, but I cannot identify why. Could someone help?