#python #git #dictionary
#python #git #словарь
Вопрос:
я работаю над тем, чтобы не получать коммиты из репозитория в виде словаря, пока я запускаю код, я получаю ошибку «элемент последовательности обновления словаря # 0 имеет длину 1; требуется 2»
def branches_of_repo(repo, owner, api):
branches = []
next = True
i = 1
while next == True:
url = api '/repos/{}/{}/branches?page={}amp;per_page=100'.format(owner, repo, i)
branch_pg = gh_session.get(url = url)
branch_pg_list = [dict(item, **{'repo_name':'{}'.format(repo)}) for item in branch_pg.json()]
branch_pg_list = [dict(item, **{'owner':'{}'.format(owner)}) for item in branch_pg_list]
branches = branches branch_pg_list
if 'Link' in branch_pg.headers:
if 'rel="next"' not in branch_pg.headers['Link']:
next = False
i = i 1
return branches
branches = json_normalize(branches_of_repo('taniarascia', 'takenote', github_api))
и я сталкиваюсь с приведенной ниже ошибкой:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-25-11cbe96472f5> in <module>
----> 1 branches = json_normalize(branches_of_repo('taniarascia', 'takenote', github_api))
<ipython-input-18-33fa60f7c673> in branches_of_repo(repo, owner, api)
6 url = api '/repos/{}/{}/branches?page={}amp;per_page=100'.format(owner, repo, i)
7 branch_pg = gh_session.get(url = url)
----> 8 branch_pg_list = [dict(item, **{'repo_name':'{}'.format(repo)}) for item in branch_pg.json()]
9 branch_pg_list = [dict(item, **{'owner':'{}'.format(owner)}) for item in branch_pg_list]
10 branches = branches branch_pg_list
<ipython-input-18-33fa60f7c673> in <listcomp>(.0)
6 url = api '/repos/{}/{}/branches?page={}amp;per_page=100'.format(owner, repo, i)
7 branch_pg = gh_session.get(url = url)
----> 8 branch_pg_list = [dict(item, **{'repo_name':'{}'.format(repo)}) for item in branch_pg.json()]
9 branch_pg_list = [dict(item, **{'owner':'{}'.format(owner)}) for item in branch_pg_list]
10 branches = branches branch_pg_list
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Комментарии:
1. Я бы проверил, что вывод branch_pg.json() и убедитесь, что понимание списка понимания, которое у вас есть, работает. Также вы должны быть в состоянии сделать
**{'repo_name':'{}'.format(repo), 'owner':'{}'.format(owner)}
это вместо того, чтобы иметь это в двух строках2. но **{‘repo_name’:'{}’.format(repo), ‘owner’:'{}’.format(owner)} разные