已经有一些好的解决方案,但是如果您使用
requests,请遵循Github的API。
所有内容的端点是
GET /repos/:owner/:repo/contents/:path
但是请记住,Github API的默认行为是使用编码内容
base64。
在您的情况下,您可以执行以下操作:
#!/usr/bin/env python3import base64import requestsurl = 'https://api.github.com/repos/{user}/{repo_name}/contents/{path_to_file}'req = requests.get(url)if req.status_pre == requests.pres.ok: req = req.json() # the response is a JSON # req is now a dict with keys: name, encoding, url, size ... # and content. But it is enpred with base64. content = base64.deprestring(req['content'])else: print('Content was not found.')


