I am trying to create a release and upload all files with a specific ending as an asset. My code is as follows:
# This uploads all apkg files in the current directory to a release on GitHub.
import github
import dotenv
import os
import glob
dotenv.load_dotenv()
g = github.Github(os.getenv("GITHUB_TOKEN"))
repo = g.get_repo("Vuizur/tatoeba-to-anki")
release = None
for r in repo.get_releases():
if r.title == "latest":
print("Found a release with the name 'latest'")
release = r
break
if release is None:
print("Creating a new release")
release = repo.create_git_release(
"latest",
"latest",
"latest",
draft=False,
prerelease=False,
)
# Now delete all files in the release
for asset in release.get_assets():
asset.delete_asset()
print("Deleted all files in the release")
print(f"Uploading {len(glob.glob('*.apkg'))} files to the release...")
# Now upload all files in the current directory
for file in glob.glob("*.apkg"):
print(f"Uploading {file}")
release.upload_asset(file)
print(f"Finished uploading {file}")
Unfortunately, this doesn't quite work. When I run the code, it prints:
Found a release with the name 'latest'
Deleted all files in the release
Uploading 37 files to the release...
Uploading ara_eng.apkg
It successfully uploads the first asset, which is perfectly visible on Github. However, after that nothing happens, and no network traffic is visible on the task manager. It is as if the upload_asset
function never returns despite having finished.
I then though that it might be PyGithub's fault, so I replaced the upload_release call with:
for file in glob.glob("*.apkg"):
print(f"Uploading {file}")
release_id = release.id
url = f"https://uploads.github.com/repos/Vuizur/tatoeba-to-anki/releases/{release_id}/assets?name={file}"
headers = {
"Accept": "application/vnd.github.v3+json",
# apkg files are zip files
"Content-Type": "application/zip",
# the authorization token
"Authorization": f"token {os.getenv('GITHUB_TOKEN')}",
}
with open(file, "rb") as f:
response = requests.post(url, headers=headers, data=f)
print(response)
But this shows exactly the same behaviour as when using PyGithub.
I also read a bit about shenanigans with IPV4/6, so I tried disabling IPV6 using requests.packages.urllib3.util.connection.HAS_IPV6 = False
at the beginning of my script, but this did not work either.
Thanks for the help!
System: Windows 11 Python: 3.10.9