Kaggle / kaggle-api

Official Kaggle API
Apache License 2.0
6.12k stars 1.08k forks source link

'file' object has no attribute 'readable' error in version 1.5.0 #115

Closed JohannesBuchner closed 1 year ago

JohannesBuchner commented 5 years ago

I cannot submit any longer with the pypi kaggle commands. I get the following error:

$ kaggle competitions submit -c PLAsTiCC-2018 -f myfile.csv.gz -m 'mymessage' 
  0%|                                                                                                                                                    | 0.00/131M [00:00<?, ?B/s]
'file' object has no attribute 'readable'
Could not submit to competition

The file is readable. This is on CentOS Linux release 7.4.1708, with Python 2.7.

pip install kaggle --upgrade did not help. Since it looks like some progressbar, I tried uninstalling tqdm and reinstalling it, but that did not help either.

ghost commented 5 years ago

I can't reproduce this with either a plain csv or a zip. I tried it with the sample submission for the same competition. We do not support Python 2 for the API, however. I don't know for sure if that is the problem, but it's possible.

JohannesBuchner commented 5 years ago

Apparently dput (https://salsa.debian.org/debian/dput) had a similar issue (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=836456) They solved it with this patch:

-    if isinstance(stream, io.TextIOBase):
+    if isinstance(stream, file):
+        # Python 2 `file` type doesn't work with the `io` types. Open
+        # the file again with a type we can use.
+        if stream.mode.endswith('b'):
+            text_mode = stream.mode[:-1]
+        else:
+            text_mode = stream.mode
+        fileno = os.dup(stream.fileno())
+        result = io.open(fileno, mode=text_mode, encoding=encoding)
+    elif isinstance(stream, io.TextIOBase):
         result = stream

It has something to do with IO streaming. This used to work a a few weeks ago.

JohannesBuchner commented 5 years ago

Found a simple fix, see PR.

ghost commented 5 years ago

I merged that in, but please be aware that I'm generally not going to make any changes to accommodate Python 2.