我想用Github API更新文件并将其提交到分支中。我有麻烦创建提交。 SHA与预期的不符。如何用Python中的Github api字符串计算SHA?
{
'documentation_url': 'https://developer.github.com/enterprise/2.7/v3/repos/contents/',
'message': 'pom.xml does not match de42fdd980f9b8067a2af982de46b8d5547e4597'
}
我做了以下内容:
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)
我不喜欢用一个lib这样做是为了更好地了解发生了什么。可能SHA没有正确生成,但我无法确定原因。有人可以帮忙吗?
你确定你需要校验base64编码的文件版本? –