如何解决Pygithub无法使用用户名和密码登录,如何解决?
Traceback (most recent call last):
File "D:\Dev\PetProjects\PythonPetProjects\OneClickGitHub\oneclickgithub\main.py",line 31,in <module>
repo = g.get_user().get_repo(github_creds['rep'])
File "C:\Users\PANDEMIC\AppData\Local\pypoetry\Cache\virtualenvs\oneclickgithub-UDpxgjZD-py3.9\lib\site-packages\github\AuthenticatedUser.py",line 1019,in get_repo
"GET",f"/repos/{self.login}/{name}"
File "C:\Users\PANDEMIC\AppData\Local\pypoetry\Cache\virtualenvs\oneclickgithub-UDpxgjZD-py3.9\lib\site-packages\github\AuthenticatedUser.py",line 231,in login
self._completeIfNotSet(self._login)
File "C:\Users\PANDEMIC\AppData\Local\pypoetry\Cache\virtualenvs\oneclickgithub-UDpxgjZD-py3.9\lib\site-packages\github\GithubObject.py",line 297,in _completeIfNotSet
self._completeIfNeeded()
File "C:\Users\PANDEMIC\AppData\Local\pypoetry\Cache\virtualenvs\oneclickgithub-UDpxgjZD-py3.9\lib\site-packages\github\GithubObject.py",line 301,in _completeIfNeeded
self.__complete()
File "C:\Users\PANDEMIC\AppData\Local\pypoetry\Cache\virtualenvs\oneclickgithub-UDpxgjZD-py3.9\lib\site-packages\github\GithubObject.py",line 308,in __complete
headers,data = self._requester.requestJsonAndCheck("GET",self._url.value)
File "C:\Users\PANDEMIC\AppData\Local\pypoetry\Cache\virtualenvs\oneclickgithub-UDpxgjZD-py3.9\lib\site-packages\github\Requester.py",line 353,in requestJsonAndCheck
return self.__check(
File "C:\Users\PANDEMIC\AppData\Local\pypoetry\Cache\virtualenvs\oneclickgithub-UDpxgjZD-py3.9\lib\site-packages\github\Requester.py",line 378,in __check
raise self.__createException(status,responseHeaders,output)
github.GithubException.GithubException: 401 {"message": "Requires authentication","documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"}
这是代码
import os
import sys
import json
import requests
from github import Github
def get_files(dir_name: str = '.') -> list:
list_of_files = os.listdir(dir_name)
complete_file_list = list()
for file in list_of_files:
complete_filepath = os.path.join(dir_name,file)
if os.path.isdir(complete_filepath):
complete_file_list = complete_file_list + get_files(complete_filepath)
else:
complete_file_list.append(complete_filepath)
return complete_file_list
def get_data_from_json(filepath: str) -> dict:
with open(filepath,encoding='utf-8') as json_file:
return json.load(json_file)
github_creds = get_data_from_json('creds.json')
g = Github(github_creds['login'],github_creds['password'])
repo = g.get_user().get_repo(github_creds['rep'])
all_files = []
try:
contents = repo.get_contents("")
while contents:
file_content = contents.pop(0)
if file_content.type == "dir":
contents.extend(repo.get_contents(file_content.path))
else:
file = file_content
all_files.append(str(file).replace('ContentFile(path="','').replace('")',''))
except:
print('Repository is empty')
def get_file_content(filepath: str) -> str:
with open(filepath,'r') as file:
return file.read()
files = get_files('.')
for file in files:
current_file_content = get_file_content(file)
if file in all_files:
contents = repo.get_contents(file)
repo.update_file(contents.path,"committing files",current_file_content,contents.sha,branch=github_creds['branch'])
print(file + ' UPDATED')
else:
repo.create_file(file,branch=github_creds['branch'])
print(file + ' CREATED')
看起来你的帖子主要是代码;请添加更多详细信息。看起来您的帖子主要是代码;请添加更多详细信息。看起来您的帖子主要是代码;请添加更多详细信息。看起来您的帖子主要是代码;请添加更多详细信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。