【发布时间】:2022-10-12 21:21:34
【问题描述】:
我想使用 Pygithub 将图像文件上传到我的 Github 存储库。
from github import Github
g=Github("My Git Token")
repo=g.get_repo("My Repo")
content=repo.get_contents("")
f=open("1.png")
img=f.read()
repo.create_file("1.png","commit",img)
但我收到以下错误:
File "c:\Users\mjjha\Documents\Checkrow\tempCodeRunnerFile.py", line 10, in <module>
img=f.read()
File "C:\Program Files\Python310\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 119: character maps to <undefined>
此方法适用于文本文件。但我无法将图像文件上传到我的存储库。
当我使用 open-CV 读取图像文件时,出现以下错误:
assert isinstance(content, (str, bytes))
AssertionError
我在使用 cv2 时的代码是:
from github import Github
import cv2
g=Github("")
repo=g.get_repo("")
content=repo.get_contents("")
f=cv2.imread("1.png")
img=f
repo.create_file("1.png","commit",img)
我认为 createFile() 仅将字符串作为参数,因此会出现这些错误。
有没有办法使用 Pygithub(或任何库)将图像文件上传到 Github?
【问题讨论】:
标签: python github github-pages github-api pygithub