Skip to content

Commit 4424f61

Browse files
committed
FIX upload all xml files as files (not as post argument)
1 parent 785213f commit 4424f61

4 files changed

Lines changed: 37 additions & 26 deletions

File tree

openml/_api_calls.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .exceptions import OpenMLServerError
88

99

10-
def _perform_api_call(call, data=None, file_dictionary=None,
10+
def _perform_api_call(call, file_dictionary=None,
1111
file_elements=None, add_authentication=True):
1212
"""
1313
Perform an API call at the OpenML server.
@@ -18,11 +18,14 @@ def _read_url(self, url, add_authentication=False, data=None, filePath=None):
1818
----------
1919
call : str
2020
The API call. For example data/list
21-
data : dict (default=None)
22-
Dictionary containing data which will be sent to the OpenML
23-
server via a POST request.
24-
**kwargs
25-
Further arguments which are appended as GET arguments.
21+
file_dictionary : dict
22+
Mapping of {filename: path} of files which should be uploaded to the
23+
server.
24+
file_elements : dict
25+
Mapping of {filename: str} of strings which should be uploaded as
26+
files to the server.
27+
add_authentication : bool
28+
Whether to add authentication (api key) to the request.
2629
2730
Returns
2831
-------
@@ -36,16 +39,16 @@ def _read_url(self, url, add_authentication=False, data=None, filePath=None):
3639
url += "/"
3740
url += call
3841
if file_dictionary is not None or file_elements is not None:
39-
return _read_url_files(url, data=data, file_dictionary=file_dictionary,
42+
return _read_url_files(url, file_dictionary=file_dictionary,
4043
file_elements=file_elements)
41-
return _read_url(url, data=data)
44+
return _read_url(url)
4245

4346

44-
def _read_url_files(url, data=None, file_dictionary=None, file_elements=None):
47+
def _read_url_files(url, file_dictionary=None, file_elements=None):
4548
"""do a post request to url with data None, file content of
4649
file_dictionary and sending file_elements as files"""
47-
if data is None:
48-
data = {}
50+
51+
data = {}
4952
data['api_key'] = config.apikey
5053
if file_elements is None:
5154
file_elements = {}
@@ -78,9 +81,9 @@ def _read_url_files(url, data=None, file_dictionary=None, file_elements=None):
7881
return response.status_code, response.text
7982

8083

81-
def _read_url(url, data=None):
82-
if data is None:
83-
data = {}
84+
def _read_url(url):
85+
86+
data = {}
8487
data['api_key'] = config.apikey
8588

8689
# Using requests.post sets header 'Accept-encoding' automatically to

openml/datasets/dataset.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import gzip
2+
import logging
23
import os
34
import sys
4-
import logging
5+
56
import arff
67

78
import numpy as np
@@ -267,12 +268,17 @@ def publish(self):
267268
return_value : string
268269
xml return from server
269270
"""
270-
data = {'description': self._to_xml()}
271+
272+
file_elements = {'description': self._to_xml()}
273+
file_dictionary = {}
274+
271275
if self.data_file is not None:
272-
return_code, return_value = _perform_api_call(
273-
"/data/", data=data, file_dictionary={'dataset': self.data_file})
274-
else:
275-
return_code, return_value = _perform_api_call("/data/", data=data)
276+
file_dictionary['dataset'] = self.data_file
277+
278+
return_code, return_value = _perform_api_call(
279+
"/data/", file_dictionary=file_dictionary,
280+
file_elements=file_elements)
281+
276282
return return_code, return_value
277283

278284
def _to_xml(self):

openml/flows/flow.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ def publish(self):
8181
https://github.com/openml/website/blob/master/openml_OS/views/pages/rest_api/xsd/openml.implementation.upload.xsd
8282
"""
8383
xml_description = self._generate_flow_xml()
84-
data = {'description': xml_description, 'source': self.source}
84+
85+
file_elements = {'description': xml_description} #, 'source': self.source}
8586
return_code, return_value = _perform_api_call(
86-
"/flow/", data=data)
87+
"flow/", file_elements=file_elements)
8788
return return_code, return_value
8889

8990
def _ensure_flow_exists(self):
@@ -137,7 +138,7 @@ def _check_flow_exists(name, version):
137138
raise ValueError('Argument \'version\' should be a non-empty string')
138139

139140
return_code, xml_response = _perform_api_call(
140-
"/flow/exists/%s/%s" % (name, version))
141+
"flow/exists/%s/%s" % (name, version))
141142
# TODO check with latest version of code if this raises an exception
142143
if return_code != 200:
143144
# fixme raise appropriate error

openml/runs/run.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ def publish(self):
7979
"""
8080
predictions = arff.dumps(self._generate_arff())
8181
description_xml = self._create_description_xml()
82-
data = {'predictions': ("predictions.csv", predictions),
83-
'description': ("description.xml", description_xml)}
82+
print(description_xml)
83+
file_elements = {'predictions': ("predictions.csv", predictions),
84+
'description': ("description.xml", description_xml)}
8485
return_code, return_value = _perform_api_call(
85-
"/run/", file_elements=data)
86+
"/run/", file_elements=file_elements)
8687
return return_code, return_value
8788

8889
def _create_description_xml(self):

0 commit comments

Comments
 (0)