Skip to content

Commit a3ac9a9

Browse files
committed
Update to 1.5.0
1 parent dedde37 commit a3ac9a9

File tree

7 files changed

+68
-31
lines changed

7 files changed

+68
-31
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,3 @@ target/
6262

6363
#Ipython Notebook
6464
.ipynb_checkpoints
65-
66-
# Pycharm
67-
.idea

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
====
33

4+
#### 1.5.0
5+
Release date: 10/19/18
6+
* Update API to work with new competitions submissions backend. This change will force old API clients to update.
7+
* Update error message when config file is not found.
8+
49
#### 1.4.7.1
510
Release date: 8/28/18
611
* Fix host

KaggleSwagger.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ paths:
118118
description: Error
119119
schema:
120120
$ref: '#/definitions/Error'
121-
/competitions/submissions/url/{contentLength}/{lastModifiedDateUtc}:
121+
/competitions/{id}/submissions/url/{contentLength}/{lastModifiedDateUtc}:
122122
post:
123123
tags:
124124
- kaggle
@@ -133,7 +133,12 @@ paths:
133133
name: fileName
134134
required: false
135135
type: string
136-
description: Competition submission file name
136+
description: Competition submission file name
137+
- in: path
138+
name: id
139+
required: true
140+
type: string
141+
description: Competition name, as it appears in the competition's URL
137142
- in: path
138143
name: contentLength
139144
required: true

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Official API for https://www.kaggle.com, accessible using a command line tool im
44

55
Beta release - Kaggle reserves the right to modify the API functionality currently offered.
66

7+
IMPORTANT: Competitions submissions using an API version prior to 1.5.0 may not work. If you are encountering difficulties with submitting to competitions, please check your version with `kaggle --version`. If it is below 1.5.0, please update with `pip install kaggle --upgrade`.
8+
79
## Installation
810

911
Ensure you have Python 3 and the package manager `pip` installed.

kaggle/api/kaggle_api.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -853,15 +853,16 @@ def competitions_submissions_upload_with_http_info(self, file, guid, content_len
853853
_request_timeout=params.get('_request_timeout'),
854854
collection_formats=collection_formats)
855855

856-
def competitions_submissions_url(self, content_length, last_modified_date_utc, **kwargs): # noqa: E501
856+
def competitions_submissions_url(self, id, content_length, last_modified_date_utc, **kwargs): # noqa: E501
857857
"""Generate competition submission URL # noqa: E501
858858
859859
This method makes a synchronous HTTP request by default. To make an
860860
asynchronous HTTP request, please pass async_req=True
861-
>>> thread = api.competitions_submissions_url(content_length, last_modified_date_utc, async_req=True)
861+
>>> thread = api.competitions_submissions_url(id, content_length, last_modified_date_utc, async_req=True)
862862
>>> result = thread.get()
863863
864864
:param async_req bool
865+
:param str id: Competition name, as it appears in the competition's URL (required)
865866
:param int content_length: Content length of file in bytes (required)
866867
:param int last_modified_date_utc: Last modified date of file in milliseconds since epoch in UTC (required)
867868
:param str file_name: Competition submission file name
@@ -871,20 +872,21 @@ def competitions_submissions_url(self, content_length, last_modified_date_utc, *
871872
"""
872873
kwargs['_return_http_data_only'] = True
873874
if kwargs.get('async_req'):
874-
return self.competitions_submissions_url_with_http_info(content_length, last_modified_date_utc, **kwargs) # noqa: E501
875+
return self.competitions_submissions_url_with_http_info(id, content_length, last_modified_date_utc, **kwargs) # noqa: E501
875876
else:
876-
(data) = self.competitions_submissions_url_with_http_info(content_length, last_modified_date_utc, **kwargs) # noqa: E501
877+
(data) = self.competitions_submissions_url_with_http_info(id, content_length, last_modified_date_utc, **kwargs) # noqa: E501
877878
return data
878879

879-
def competitions_submissions_url_with_http_info(self, content_length, last_modified_date_utc, **kwargs): # noqa: E501
880+
def competitions_submissions_url_with_http_info(self, id, content_length, last_modified_date_utc, **kwargs): # noqa: E501
880881
"""Generate competition submission URL # noqa: E501
881882
882883
This method makes a synchronous HTTP request by default. To make an
883884
asynchronous HTTP request, please pass async_req=True
884-
>>> thread = api.competitions_submissions_url_with_http_info(content_length, last_modified_date_utc, async_req=True)
885+
>>> thread = api.competitions_submissions_url_with_http_info(id, content_length, last_modified_date_utc, async_req=True)
885886
>>> result = thread.get()
886887
887888
:param async_req bool
889+
:param str id: Competition name, as it appears in the competition's URL (required)
888890
:param int content_length: Content length of file in bytes (required)
889891
:param int last_modified_date_utc: Last modified date of file in milliseconds since epoch in UTC (required)
890892
:param str file_name: Competition submission file name
@@ -893,7 +895,7 @@ def competitions_submissions_url_with_http_info(self, content_length, last_modif
893895
returns the request thread.
894896
"""
895897

896-
all_params = ['content_length', 'last_modified_date_utc', 'file_name'] # noqa: E501
898+
all_params = ['id', 'content_length', 'last_modified_date_utc', 'file_name'] # noqa: E501
897899
all_params.append('async_req')
898900
all_params.append('_return_http_data_only')
899901
all_params.append('_preload_content')
@@ -908,6 +910,10 @@ def competitions_submissions_url_with_http_info(self, content_length, last_modif
908910
)
909911
params[key] = val
910912
del params['kwargs']
913+
# verify the required parameter 'id' is set
914+
if ('id' not in params or
915+
params['id'] is None):
916+
raise ValueError("Missing the required parameter `id` when calling `competitions_submissions_url`") # noqa: E501
911917
# verify the required parameter 'content_length' is set
912918
if ('content_length' not in params or
913919
params['content_length'] is None):
@@ -920,6 +926,8 @@ def competitions_submissions_url_with_http_info(self, content_length, last_modif
920926
collection_formats = {}
921927

922928
path_params = {}
929+
if 'id' in params:
930+
path_params['id'] = params['id'] # noqa: E501
923931
if 'content_length' in params:
924932
path_params['contentLength'] = params['content_length'] # noqa: E501
925933
if 'last_modified_date_utc' in params:
@@ -947,7 +955,7 @@ def competitions_submissions_url_with_http_info(self, content_length, last_modif
947955
auth_settings = ['basicAuth'] # noqa: E501
948956

949957
return self.api_client.call_api(
950-
'/competitions/submissions/url/{contentLength}/{lastModifiedDateUtc}', 'POST',
958+
'/competitions/{id}/submissions/url/{contentLength}/{lastModifiedDateUtc}', 'POST',
951959
path_params,
952960
query_params,
953961
header_params,

kaggle/api/kaggle_api_extended.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161

6262
class KaggleApi(KaggleApi):
63-
__version__ = '1.4.7.1'
63+
__version__ = '1.5.0'
6464

6565
CONFIG_NAME_PROXY = 'proxy'
6666
CONFIG_NAME_COMPETITION = 'competition'
@@ -109,13 +109,13 @@ def authenticate(self):
109109
config_data = self.read_config_file(config_data)
110110
else:
111111
raise IOError('Could not find {}. Make sure it\'s located in'
112-
' {}. Or use the environment method.'
113-
.format(self.config_file, self.config_dir))
112+
' {}. Or use the environment method.'.format(
113+
self.config_file, self.config_dir))
114114

115115
# Step 3: load into configuration!
116116
self._load_config(config_data)
117117

118-
def read_config_environment(self, config_data={}, quiet=False):
118+
def read_config_environment(self, config_data=None, quiet=False):
119119
"""read_config_environment is the second effort to get a username
120120
and key to authenticate to the Kaggle API. The environment keys
121121
are equivalent to the kaggle.json file, but with "KAGGLE_" prefix
@@ -129,6 +129,8 @@ def read_config_environment(self, config_data={}, quiet=False):
129129

130130
# Add all variables that start with KAGGLE_ to config data
131131

132+
if config_data is None:
133+
config_data = {}
132134
for key, val in os.environ.items():
133135
if key.startswith('KAGGLE_'):
134136
config_key = key.replace('KAGGLE_', '', 1).lower()
@@ -187,7 +189,7 @@ def _load_config(self, config_data):
187189
'https://github.com/Kaggle/kaggle-api#api-credentials ' +
188190
'for instructions.')
189191

190-
def read_config_file(self, config_data={}, quiet=False):
192+
def read_config_file(self, config_data=None, quiet=False):
191193
"""read_config_file is the first effort to get a username
192194
and key to authenticate to the Kaggle API. Since we can get the
193195
username and password from the environment, it's not required.
@@ -198,7 +200,8 @@ def read_config_file(self, config_data={}, quiet=False):
198200
password, if defined
199201
quiet: suppress verbose print of output (default is False)
200202
"""
201-
config_data = {}
203+
if config_data is None:
204+
config_data = {}
202205

203206
if os.path.exists(self.config):
204207

@@ -211,7 +214,7 @@ def read_config_file(self, config_data={}, quiet=False):
211214
'users on this system! To fix this, you can run' +
212215
'\'chmod 600 {}\''.format(self.config))
213216

214-
with open(self.config, 'r') as f:
217+
with open(self.config) as f:
215218
config_data = json.load(f)
216219
except:
217220
pass
@@ -458,18 +461,35 @@ def competition_submit(self, file_name, message, competition, quiet=False):
458461
else:
459462
url_result = self.process_response(
460463
self.competitions_submissions_url_with_http_info(
464+
id=competition,
461465
file_name=os.path.basename(file_name),
462466
content_length=os.path.getsize(file_name),
463-
last_modified_date_utc=int(
464-
os.path.getmtime(file_name) * 1000)))
465-
url_result_list = url_result['createUrl'].split('/')
466-
upload_result = self.process_response(
467-
self.competitions_submissions_upload_with_http_info(
468-
file=file_name,
469-
guid=url_result_list[-3],
470-
content_length=url_result_list[-2],
471-
last_modified_date_utc=url_result_list[-1]))
472-
upload_result_token = upload_result['token']
467+
last_modified_date_utc=int(os.path.getmtime(file_name))))
468+
469+
# Temporary while new worker is gradually turned on. 'isComplete'
470+
# exists on the old DTO but not the new, so this is an hacky but
471+
# easy solution to figure out which submission logic to use
472+
if 'isComplete' in url_result:
473+
# Old submissions path
474+
url_result_list = url_result['createUrl'].split('/')
475+
upload_result = self.process_response(
476+
self.competitions_submissions_upload_with_http_info(
477+
file=file_name,
478+
guid=url_result_list[-3],
479+
content_length=url_result_list[-2],
480+
last_modified_date_utc=url_result_list[-1]))
481+
upload_result_token = upload_result['token']
482+
else:
483+
# New submissions path!
484+
success = self.upload_complete(file_name,
485+
url_result['createUrl'], quiet)
486+
if not success:
487+
# Actual error is printed during upload_complete. Not
488+
# ideal but changing would not be backwards compatible
489+
return "Could not submit to competition"
490+
491+
upload_result_token = url_result['token']
492+
473493
submit_result = self.process_response(
474494
self.competitions_submissions_submit_with_http_info(
475495
id=competition,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
setup(
2121
name='kaggle',
22-
version='1.4.7.1',
22+
version='1.5.0',
2323
description='Kaggle API',
2424
long_description=
2525
('Official API for https://www.kaggle.com, accessible using a command line '

0 commit comments

Comments
 (0)