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 · 1520 次点击
    这是一个创建于 838 天前的主题,其中的信息可能已经有所发展或是发生改变。
    根据这个教程想备份 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   ·   实用小工具   ·   2787 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 07:20 · PVG 15:20 · LAX 23:20 · JFK 02:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.