V 友们 脚本里如何传入 GitHub api 参数 求指点 谢谢 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
notgoda
V2EX    Python

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

  •  
  •   notgoda 2022-08-08 20:51:46 +08:00 1853 次点击
    这是一个创建于 1235 天前的主题,其中的信息可能已经有所发展或是发生改变。
    根据这个教程想备份 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")
    oott123
        1
    oott123  
       2022-08-08 23:51:24 +08:00
    https://github.com/settings/tokens 到这新建一个
    然后 echo "你的 PAT" > ~/.gist
    notgoda
        2
    notgoda  
    OP
       2022-08-09 00:16:56 +08:00   1
    @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'
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5750 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 29ms UTC 06:14 PVG 14:14 LAX 22:14 JFK 01:14
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86