0

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.

4
  • How big is this file? Github has a size limit and Git does not perform well with large binary files. Consider adding it to a release instead, or use Large File Support. Commented Aug 6, 2024 at 1:50
  • Also, you're assuming every exception means the file does not exist. You should check for specific exceptions and act accordingly. Commented Aug 6, 2024 at 1:53
  • Thanks for your comments!. This file is around 100 MB. I already have managed this folder with Git large file support. Will try to add it to a release. Commented Aug 6, 2024 at 2:22
  • repo.update_file does not use Git. It uses the Github API endpoint Create 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. Commented Aug 6, 2024 at 16:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.