summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gitlab/__init__.py14
-rw-r--r--gitlab/v4/objects/__init__.py6
-rw-r--r--requirements.txt1
-rw-r--r--setup.py2
4 files changed, 13 insertions, 10 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 960f086..98c4144 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -27,9 +27,11 @@ import gitlab.config
from gitlab.const import * # noqa
from gitlab.exceptions import * # noqa
from gitlab import utils # noqa
+from requests_toolbelt.multipart.encoder import MultipartEncoder
+
__title__ = "python-gitlab"
-__version__ = "2.5.0"
+__version__ = "2.6.0"
__author__ = "Gauvain Pocentek"
__email__ = "gauvainpocentek@gmail.com"
__license__ = "LGPL3"
@@ -496,9 +498,11 @@ class Gitlab(object):
# We need to deal with json vs. data when uploading files
if files:
- data = post_data
json = None
- del opts["headers"]["Content-type"]
+ post_data["file"] = files.get("file")
+ post_data["avatar"] = files.get("avatar")
+ data = MultipartEncoder(post_data)
+ opts["headers"]["Content-type"] = data.content_type
else:
json = post_data
data = None
@@ -509,9 +513,7 @@ class Gitlab(object):
# The Requests behavior is right but it seems that web servers don't
# always agree with this decision (this is the case with a default
# gitlab installation)
- req = requests.Request(
- verb, url, json=json, data=data, params=params, files=files, **opts
- )
+ req = requests.Request(verb, url, json=json, data=data, params=params, **opts)
prepped = self.session.prepare_request(req)
prepped.url = utils.sanitized_url(prepped.url)
settings = self.session.merge_environment_settings(
diff --git a/gitlab/v4/objects/__init__.py b/gitlab/v4/objects/__init__.py
index f42c60b..6184440 100644
--- a/gitlab/v4/objects/__init__.py
+++ b/gitlab/v4/objects/__init__.py
@@ -1615,7 +1615,7 @@ class GroupManager(CRUDMixin, RESTManager):
Returns:
dict: A representation of the import status.
"""
- files = {"file": ("file.tar.gz", file)}
+ files = {"file": ("file.tar.gz", file, "application/octet-stream")}
data = {"path": path, "name": name}
if parent_id is not None:
data["parent_id"] = parent_id
@@ -5488,8 +5488,8 @@ class ProjectManager(CRUDMixin, RESTManager):
Returns:
dict: A representation of the import status.
"""
- files = {"file": ("file.tar.gz", file)}
- data = {"path": path, "overwrite": overwrite}
+ files = {"file": ("file.tar.gz", file, "application/octet-stream")}
+ data = {"path": path, "overwrite": str(overwrite)}
if override_params:
for k, v in override_params.items():
data["override_params[%s]" % k] = v
diff --git a/requirements.txt b/requirements.txt
index 989b995..d1fa0be 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +1,2 @@
requests==2.24.0
+requests-toolbelt>=0.9.1
diff --git a/setup.py b/setup.py
index 9626083..935ebae 100644
--- a/setup.py
+++ b/setup.py
@@ -26,7 +26,7 @@ setup(
license="LGPLv3",
url="https://github.com/python-gitlab/python-gitlab",
packages=find_packages(),
- install_requires=["requests>=2.22.0"],
+ install_requires=["requests>=2.22.0", "requests-toolbelt>=0.9.1"],
python_requires=">=3.6.0",
entry_points={"console_scripts": ["gitlab = gitlab.cli:main"]},
classifiers=[