【发布时间】:2018-12-19 00:12:27
【问题描述】:
嗨,我目前正在尝试解码从 Github API /:username/:repo/contents/:filepath 返回的 base64
返回一个json对象
{ "type": "file", "encoding": "base64", "size": 5362, "name": "README.md", "path": "README.md", "content": "encoded content ...", "sha": "3d21ec53a331a6f037a91c368710b99387d012c1", "url": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md", "git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6>f037a91c368710b99387d012c1", "html_url": >"https://github.com/octokit/octokit.rb/blob/master/README.md", "download_url": >"https://raw.githubusercontent.com/octokit/octokit.rb/master/README.md", "_links": { "git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/3d21ec53a331a6f037a91c368710b99387d012c1", "self": "https://api.github.com/repos/octokit/octokit.rb/contents/README.md", "html": "https://github.com/octokit/octokit.rb/blob/master/README.md" }}
内容被编码为 base64,但当我尝试解码时 - 它给了我随机字符
from googleapiclient import discovery
from goйɽ́Ё!ɽ)ɽwWF&6ƖVB6W'f6U66VB'B6W'f6T66[ܙY[X[[\ܝX]QgTS_DISCOVERY_URL='https://sheets.googleapis.c͍ٕɕٕͥМ)M.....
这是我的代码:
try: result = urlfetch.fetch(url, headers={"accept": >"application/vnd.github.v3+json"}) if result.status_code == 200: decoded_content = base64.b64decode(result.content) print(decoded_content) else: self.response.status_code = result.status_code
【问题讨论】:
标签: python github google-cloud-platform web2py github-api