88from .exceptions import OpenMLServerError
99
1010
11- def _perform_api_call (call , file_dictionary = None ,
11+ def _perform_api_call (call , data = None , file_dictionary = None ,
1212 file_elements = None , add_authentication = True ):
1313 """
1414 Perform an API call at the OpenML server.
@@ -19,6 +19,8 @@ def _read_url(self, url, add_authentication=False, data=None, filePath=None):
1919 ----------
2020 call : str
2121 The API call. For example data/list
22+ data : dict
23+ Dictionary with post-request payload.
2224 file_dictionary : dict
2325 Mapping of {filename: path} of files which should be uploaded to the
2426 server.
@@ -39,17 +41,20 @@ def _read_url(self, url, add_authentication=False, data=None, filePath=None):
3941 if not url .endswith ("/" ):
4042 url += "/"
4143 url += call
44+
45+ url = url .replace ('=' , '%3d' )
46+
4247 if file_dictionary is not None or file_elements is not None :
43- return _read_url_files (url , file_dictionary = file_dictionary ,
48+ return _read_url_files (url , data = data , file_dictionary = file_dictionary ,
4449 file_elements = file_elements )
45- return _read_url (url )
50+ return _read_url (url , data )
4651
4752
48- def _read_url_files (url , file_dictionary = None , file_elements = None ):
49- """do a post request to url with data None , file content of
53+ def _read_url_files (url , data = None , file_dictionary = None , file_elements = None ):
54+ """do a post request to url with data, file content of
5055 file_dictionary and sending file_elements as files"""
5156
52- data = {}
57+ data = {} if data is None else data
5358 data ['api_key' ] = config .apikey
5459 if file_elements is None :
5560 file_elements = {}
@@ -75,23 +80,24 @@ def _read_url_files(url, file_dictionary=None, file_elements=None):
7580 # 'gzip,deflate'
7681 response = requests .post (url , data = data , files = file_elements )
7782 if response .status_code != 200 :
78- raise OpenMLServerError (response .text )
83+ raise OpenMLServerError (( 'Status code: %d \n ' % response . status_code ) + response .text )
7984 if 'Content-Encoding' not in response .headers or \
8085 response .headers ['Content-Encoding' ] != 'gzip' :
8186 warnings .warn ('Received uncompressed content from OpenML for %s.' % url )
8287 return response .status_code , response .text
8388
8489
85- def _read_url (url ):
90+ def _read_url (url , data = None ):
8691
87- data = {}
92+ data = {} if data is None else data
8893 data ['api_key' ] = config .apikey
8994
9095 # Using requests.post sets header 'Accept-encoding' automatically to
9196 # 'gzip,deflate'
9297 response = requests .post (url , data = data )
98+
9399 if response .status_code != 200 :
94- raise OpenMLServerError (response .text )
100+ raise OpenMLServerError (( 'Status code: %d \n ' % response . status_code ) + response .text )
95101 if 'Content-Encoding' not in response .headers or \
96102 response .headers ['Content-Encoding' ] != 'gzip' :
97103 warnings .warn ('Received uncompressed content from OpenML for %s.' % url )
0 commit comments