首页 > 解决方案 > 尝试通过 Python Gitlab api 将 gz 文件上传到 Gitlab

问题描述

我正在尝试通过 python gitlab api 将 .gz 文件上传到 gitlab。但是,我发现这样做的唯一文档是通过创建文件。

https://python-gitlab.readthedocs.io/en/stable/gl_objects/projects.html#id7

我已经尝试过使用我的 gz 文件,但是我得到的错误代码是 UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

f = project.files.create({'file_path': 'testfile.txt',
                          'branch': 'master',
                          'content': file_content,
                          'author_email': 'test@example.com',
                          'author_name': 'yourname',
                          'commit_message': 'Create testfile'})

我的预期结果是能够通过 API 或其他方法将 gz 文件上传到 Gitlab。

标签: python-3.xgitlab

解决方案


我最终使用 paramiko 并通过该库进行连接。我最终使用 ssh.exec_command 并键入了所有命令,后跟 \n 以解决此问题。


推荐阅读