TUT-ARG / DCASE2017-baseline-system

DCASE 2017 Baseline system
82 stars 54 forks source link

'urllib' has no attribute 'URLError' #1

Closed thisisjl closed 7 years ago

thisisjl commented 7 years ago

Hi, I am using python 3.5 and when I run task1.py, I get the error: 'urllib' has no attribute 'URLError'

URLError is included in the urllib.error module, so if I import it as from urllib.error import URLError, it works fine.

In the same way, urlretrieve is in the urllib.request module and I have to import it accordingly to make it work.

I have tried the python versions 2.7 and 3.6 and the same error appears, can it be an error in my installation?

I copy the error message as reference:

JL-MBP:applications JL$ python3 task1.py 
[I] DCASE 2017::Acoustic Scene Classification / Baseline System
[I] 
[I] Initialize [Development setup][folds]
[I] ==================================================
[I] 
[I]   System              
[I]     Name                 : DCASE 2017::Acoustic Scene Classification / Baseline System
[I]     Description          : DCASE2017 baseline (CPU) using DCASE2017 task 1 development dataset
[I]     Parameter set        : dcase2017
[I]     Setup                : Python[3.5.0], Numpy[1.12.1], sklearn[0.18.1], Keras[2.0.2], Theano[0.9.0], Librosa[0.5.0]
[I]   Dataset             
[I]     Name                 : TUT-acoustic-scenes-2017-development
[I]     Active folds         : [1, 2, 3, 4]
[I]   Evaluator           
[I]     Save path            : system/task1/evaluator
Download package list    :   0%|                             Traceback (most recent call last):                                                             | 0/14 [00:00<?, ?it/s]
  File "/Users/JL/Documents/SMC10/Master Thesis/Reference code/DCASE2017-baseline-system/dcase_framework/datasets.py", line 728, in download
    local_filename, headers = urllib.urlretrieve(
AttributeError: module 'urllib' has no attribute 'urlretrieve'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "task1.py", line 287, in <module>
    sys.exit(main(sys.argv))
  File "task1.py", line 208, in main
    app.initialize()
  File "/Users/JL/Documents/SMC10/Master Thesis/Reference code/DCASE2017-baseline-system/dcase_framework/decorators.py", line 38, in function_wrapper
    to_return = func(*args, **kwargs)
  File "/Users/JL/Documents/SMC10/Master Thesis/Reference code/DCASE2017-baseline-system/dcase_framework/application_core.py", line 534, in initialize
    self.dataset.initialize()
  File "/Users/JL/Documents/SMC10/Master Thesis/Reference code/DCASE2017-baseline-system/dcase_framework/datasets.py", line 359, in initialize
    self.download()
  File "/Users/JL/Documents/SMC10/Master Thesis/Reference code/DCASE2017-baseline-system/dcase_framework/datasets.py", line 737, in download
    except (urllib.URLError, socket.timeout) as e:
AttributeError: module 'urllib' has no attribute 'URLError'
toni-heittola commented 7 years ago

I changed the exception handling a bit and increased the socket timeout in commit e1699a4ab7cacfb17f140965cc7f6540974d038b. At least now you should see better what is causing the error.

Most likely your internet connection is causing this error. Easiest way around this it to manually download dataset packages from zenodo and place them under applications/data/TUT-acoustic-scenes-2017-development/, the system will detect these packages and it will continue processing normally.

thisisjl commented 7 years ago

Hi @toni-heittola, thanks for your quick reply.

If I apply the changes I mention above, I am able to download the data. These changes are just in dcase_framework/datasets.py:

import urllib.error
from urllib.request import urlretrieve

and in line 739: except (urllib.error.URLError, socket.timeout) as e:

I will try the your new changes and let you know as well.

thisisjl commented 7 years ago

Hi again. When I run task1.py in your latest commit, I get the following error:

(dcase-ve) h29:applications JL$ git reset --hard origin/master
HEAD is now at e1699a4 Add socket timeout, Fix error handling when downloading a file fails
(dcase-ve) h29:applications JL$ python3 task1.py 
[I] DCASE 2017::Acoustic Scene Classification / Baseline System
[I] 
[I] Initialize [Development setup][folds]
[I] ==================================================
[I] 
[I]   System              
[I]     Name                 : DCASE 2017::Acoustic Scene Classification / Baseline System
[I]     Description          : DCASE2017 baseline (CPU) using DCASE2017 task 1 development dataset
[I]     Parameter set        : dcase2017
[I]     Setup                : Python[3.6.1], Numpy[1.12.1], sklearn[0.18.1], Keras[2.0.2], Theano[0.9.0], Librosa[0.5.0]
[I]   Dataset             
[I]     Name                 : TUT-acoustic-scenes-2017-development
[I]     Active folds         : [1, 2, 3, 4]
[I]   Evaluator           
[I]     Save path            : system/task1/evaluator
Download package list    :   0%|                                 Traceback (most recent call last):                                                           | 0/14 [00:00<?, ?it/s]
  File "/Users/JL/Documents/SMC10/Master-Thesis/Reference-code/DCASE2017-baseline-system/dcase_framework/datasets.py", line 732, in download
    local_filename, headers = urllib.urlretrieve(
AttributeError: module 'urllib' has no attribute 'urlretrieve'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "task1.py", line 287, in <module>
    sys.exit(main(sys.argv))
  File "task1.py", line 208, in main
    app.initialize()
  File "/Users/JL/Documents/SMC10/Master-Thesis/Reference-code/DCASE2017-baseline-system/dcase_framework/decorators.py", line 38, in function_wrapper
    to_return = func(*args, **kwargs)
  File "/Users/JL/Documents/SMC10/Master-Thesis/Reference-code/DCASE2017-baseline-system/dcase_framework/application_core.py", line 534, in initialize
    self.dataset.initialize()
  File "/Users/JL/Documents/SMC10/Master-Thesis/Reference-code/DCASE2017-baseline-system/dcase_framework/datasets.py", line 359, in initialize
    self.download()
  File "/Users/JL/Documents/SMC10/Master-Thesis/Reference-code/DCASE2017-baseline-system/dcase_framework/datasets.py", line 745, in download
    errno=e.errno,
AttributeError: 'AttributeError' object has no attribute 'errno'

I have this error using the internet of my university, I do not think the internet connection is causing the error.

However, I could download the dataset if in dcase_framework/dataset.py I replace the imports for urllib as:

from urllib.error import URLError
from urllib.request import urlretrieve

and in line 728 (at this commit), I put this instead: local_filename, headers = urlretrieve(

and in line 737: 738 except (urllib.error.URLError, socket.timeout) as e:

Please, let me know if that is okay and can help anyone having the same issue as me.

toni-heittola commented 7 years ago

urllib has a bit different API on python 2 and 3. I addressed this issue in the commit f8dbd4da2dd8e55a8ff74ccc936ee04dd5222886.

Shamvuchandradas commented 4 years ago
except urllib.URLError:

AttributeError: module 'urllib' has no attribute 'URLError'

Ggre55 commented 1 year ago
import urllib.error
from urllib.request import urlretrieve

and in line 739: except (urllib.error.URLError, socket.timeout) as e:

Do this : import urllib.error from urllib.request import urlretrieve

and dont use 'except urllib.URLError' use this: except (urllib.error.URLError) as e: or whatever u wanna do with it just use : urllib.error.URLError