我尝试了json.dumps
所有的方法,但仍然不起作用。我不明白发生了什么事。我使用的是githubv3api,我试图用b64encode
更新一个文件,但它拒绝了我,就像拒绝约会一样
我似乎找不到问题:0
import requests
import base64
import json
def byteify(input):
if isinstance(input, dict):
return {byteify(key): byteify(value)
for key, value in input.iteritems()}
elif isinstance(input, list):
return [byteify(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input
def push_to_github(filename, branch, token):
url="http://{enterprise}/api/v3/repos/dataWrangling/weightsWebApp/contents/test.json"
base64content=base64.b64encode(open(filename,"rb").read())
data = requests.get(url+'?ref='+branch, headers = {"Authorization": "token "+token}, verify='/etc/pki/tls/certs/ca-bundle.crt').json()
sha = data['sha']
if base64content.decode('utf-8')+"\n" != data['content']:
message = {'message':'update','content': byteify(base64content),'sha': sha}
resp=requests.put(url+'?ref='+branch, headers = {"Authorization": "token "+token}, params = message, verify='/etc/pki/tls/certs/ca-bundle.crt')
print(message)
print(data)
print(sha)
print(base64content)
print(resp.text)
print(token)
print(resp.url)
else:
print("nothing to update")
我从API收到了这个消息
{"message":"Problems parsing JSON","documentation_url":"https://developer.github.com/enterprise/2.17/v3/repos/contents/#update-a-file"}
目前没有回答
相关问题 更多 >
编程相关推荐