V 友们 脚本里如何传入 GitHub api 参数 求指点 谢谢

2022-08-08 20:51:46 +08:00
 notgoda
根据这个教程想备份 gist , 安装好环境后, 执行代码 提示 找不到文件或文件夹 , 新建了个.gist 文件夹 又提示是 IsADirectoryError: [Errno 21] Is a directory: '/root/.gist'

https://jpmens.net/2019/04/03/backup-all-my-gists/

请问这脚本里如何传入 GitHub api 参数 求指点 谢谢

脚本如下 :

#!/usr/bin/env python -B

from github import Github # pip install PyGithub
import json
import os

all = []

g = Github(open(os.path.expanduser("~/.gist")).read())

for gist in g.get_user().get_gists():
all.append({
"id" : gist.id,
"description" : gist.description,
"public" : gist.public,
"clone" : gist.git_pull_url,
"updated" : gist.updated_at.isoformat(),
"url" : gist.url,
})

# yuck
os.system("git clone '{0}' repos/{1}".format(gist.git_pull_url, gist.id))

with open("index.json", "w") as f:
f.write(json.dumps(all, indent=4) + "\n")
1432 次点击
所在节点    Python
2 条回复
oott123
2022-08-08 23:51:24 +08:00
https://github.com/settings/tokens 到这新建一个
然后 echo "你的 PAT" > ~/.gist
notgoda
2022-08-09 00:16:56 +08:00
@oott123 谢谢大佬, 还是报错 , 如下 , 大佬 有空帮忙看看 .
Traceback (most recent call last):
File "all-gists.py", line 11, in <module>
for gist in g.get_user().get_gists():
File "/usr/local/lib/python3.8/dist-packages/github/PaginatedList.py", line 56, in __iter__
newElements = self._grow()
File "/usr/local/lib/python3.8/dist-packages/github/PaginatedList.py", line 67, in _grow
newElements = self._fetchNextPage()
File "/usr/local/lib/python3.8/dist-packages/github/PaginatedList.py", line 199, in _fetchNextPage
headers, data = self.__requester.requestJsonAndCheck(
File "/usr/local/lib/python3.8/dist-packages/github/Requester.py", line 354, in requestJsonAndCheck
*self.requestJson(
File "/usr/local/lib/python3.8/dist-packages/github/Requester.py", line 454, in requestJson
return self.__requestEncode(cnx, verb, url, parameters, headers, input, encode)
File "/usr/local/lib/python3.8/dist-packages/github/Requester.py", line 528, in __requestEncode
status, responseHeaders, output = self.__requestRaw(
File "/usr/local/lib/python3.8/dist-packages/github/Requester.py", line 555, in __requestRaw
response = cnx.getresponse()
File "/usr/local/lib/python3.8/dist-packages/github/Requester.py", line 127, in getresponse
r = verb(
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 665, in urlopen
httplib_response = self._make_request(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 387, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.8/http/client.py", line 1256, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/lib/python3.8/http/client.py", line 1297, in _send_request
self.putheader(hdr, value)
File "/usr/lib/python3.8/http/client.py", line 1234, in putheader
raise ValueError('Invalid header value %r' % (values[i],))
ValueError: Invalid header value b'token xxxxxxxxxxxxxxxxxxx\n'

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/871511

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX