Commit 9d7aee94 authored by Jeroen F.J. Laros's avatar Jeroen F.J. Laros

Rather dirty hack to get multipart streaming working.

parent c8e804aa
jsonschema
pyyaml
requests
requests-toolbelt
urllib3
......@@ -11,7 +11,8 @@ documentation = 'README.md'
license = 'MIT License'
keywords = []
dependencies = ['jsonschema', 'pyyaml', 'requests', 'urllib3']
dependencies = [
'jsonschema', 'pyyaml', 'requests', 'requests-toolbelt', 'urllib3']
develop_dependencies = ['fake-open', 'pytest', 'tox']
supported = [(2, 7), (3, 3), (3, 4)]
classifiers = [
......
import json
import requests
import requests_toolbelt
import sys
import urllib3
......@@ -23,7 +24,9 @@ class TransferClient(object):
except AttributeError:
sys.stderr = open('/dev/null')
def _request(self, method, endpoint, headers=None, files=None, json=None):
def _request(
self, method, endpoint, headers=None, files=None, json=None,
data=None):
"""
Handle a request.
......@@ -37,9 +40,16 @@ class TransferClient(object):
:returns dict: JSON encoded content of the response.
"""
try:
response = requests.request(method,
'https://{}/{}'.format(self.server_name, endpoint),
headers=headers, files=files, json=json, verify=self._verify)
m = None
if data:
m = requests_toolbelt.MultipartEncoder(
fields=map(
lambda x: {x[0]: (x[1].name, x[1])}, data.items())[0])
headers.update({'Content-Type': m.content_type})
response = requests.request(
method, 'https://{}/{}'.format(self.server_name, endpoint),
headers=headers, data=m, files=files, json=json,
verify=self._verify)
except requests.exceptions.SSLError:
raise OSError('SSL error, no server certificate installed?')
if not response.ok:
......@@ -111,7 +121,7 @@ class TransferClient(object):
"""
return self._request(
'post', 'transfers/{}/uploads'.format(transfer_id),
{'User-Id': user_id}, {'upload': file_handle})
{'User-Id': user_id}, data={'upload': file_handle})
def completed(self, client_id):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment