使用 github3.py 版本 0.9.5文档,我正在尝试创建一个存储库对象,但它不断返回Nonetype
,因此我无法访问存储库的内容。StackOverflow 上似乎没有任何其他帖子,或者图书馆的 GitHub 问题上的对话解决了这个问题。
AttributeError: 'NoneType' object has no attribute 'contents'
是我收到的确切错误。
在说repo = repository('Django', auth)
我尝试用fv4更改身份验证的行上,但这并没有改变任何其他内容。
#!/usr/bin/env python
from github3 import authorize, repository, login
from pprint import PrettyPrinter as ppr
import github3
from getpass import getuser
pp = ppr(indent=4)
username = 'myusername'
password = 'mypassword'
scopes = ['user', 'repo', 'admin:public_key', 'admin:repo_hook']
note = 'github3.py test'
note_url = 'http://github.com/FreddieV4'
print("Attemping authorization...")
token = id = ''
with open('CREDENTIALS.txt', 'r') as fi:
token = fi.readline().strip()
id = fi.readline().strip()
print("AUTH token {}\nAUTH id {}\n".format(token, id))
print("Attempting login...\n")
fv4 = login(username, password, token=token)
print("Login successful!", str(fv4), '\n')
print("Attempting auth...\n")
auth = fv4.authorization(id)
print("Auth successful!", auth, '\n')
print("Reading repo...\n")
repo = repository('Django', auth)
print("Repo object...{}\n\n".format(dir(repo)))
print("Repo...{}\n\n".format(repo))
contents = repo.contents('README.md')
pp.pprint('CONTENTS {}'.format(contents))
contents.update('Testing github3.py', contents)
#print("commit: ", commit)