I am trying to push a mp4 file from my local storage to my github repo using PyGithub with the following code.
from github import Github
import base64
# Authenticate to GitHub
token = "my_token"
g = Github(token)
# Get the repository
repo_name = "username/my_repo"
repo = g.get_repo(repo_name)
# Path to the local file to upload
file_path = "/video.mp4"
# Path in the repository where the file will be uploaded
repo_file_path = "video.mp4"
# Read the file content
with open(file_path, "rb") as file:
content = file.read()
# Encode the file content to base64
encoded_content = base64.b64encode(content).decode('utf-8')
# Commit the file to the repository
commit_message = "Add or update video file"
try:
contents = repo.get_contents(repo_file_path)
# Update the file
repo.update_file(contents.path, commit_message, encoded_content, contents.sha)
print(f"File '{repo_file_path}' updated successfully.")
except Exception as e:
# Create the file if it does not exist
repo.create_file(repo_file_path, commit_message, encoded_content)
print(f"File '{repo_file_path}' uploaded successfully.")
The mp4 file in the repo is managed by the Git LFS. But the upload failed.
I expected that this code can automatically upload the mp4 file. However, I get:
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=9, connect=None, read=None, redirect=None, status=None)) after connection broken by 'TimeoutError('The write operation timed out')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=8, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2406)')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=7, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2406)')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=6, connect=None, read=None, redirect=None, status=None)) after connection broken by 'TimeoutError('The write operation timed out')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=5, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2406)')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2406)')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'TimeoutError('The write operation timed out')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2406)')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2406)')': /repos/username/my_repo/contents/video.mp4
WARNING:urllib3.connectionpool:Retrying (GithubRetry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2406)')': /repos/username/my_repo/contents/video.mp4
HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /repos/username/my_repo/contents/video.mp4 (Caused by SSLError(SSLWantWriteError(3, 'The operation did not complete (write) (_ssl.c:2406)')))
Stopped
I could upload a txt file with similar codes, so it seems that this problem was due to the mp4 file.
repo.update_filedoes not use Git. It uses the Github API endpointCreate or update file contents. It's possible this does not work with LFS. I'd start by eliminating Python as a problem; try using a different HTTP client such as curl to do the upload. If it works, it's something about Python.