Search code examples
pythonwindowscmdcoursera-api

Coursera-dl not downloading classes command prompt Windows


I have been trying to install some lectures from coursera using the coursera-dl command, installed via :

pip install coursera-dl

I also did the coursera-dl.conf file, which includes my username, password, download preferences and cauth from Coursera.org. I made sure to be logged in on coursera (in ALL of my browsers!!!) I carefully write the classe's name, i.e. what follows learn/ in the url. But I encountered errors. I decided to downgrade Python from 3.9.5 to 3.8. I also changed path, in environment variables of advanced settings (control panel) to where the coursera-dl.exe file is. In addition, I have created the folder for the downloads, have the .conf file in there, and am doing the commands there (it managed to create a coursera-dl folder too, after I git cloned I think).

Anyway, I now get the error below after doing this command:

coursera-dl classical-composition

Can anyone help me please? Thank you

 Traceback (most recent call last):
      File "c:\users\leo\anaconda3\envs\spyder-env\lib\runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "c:\users\leo\anaconda3\envs\spyder-env\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "C:\Users\Leo\Anaconda3\envs\spyder-env\Scripts\coursera-dl.exe\__main__.py", line 4, in <module>
      File "c:\users\leo\anaconda3\envs\spyder-env\lib\site-packages\coursera\coursera_dl.py", line 61, in <module>
        from .cookies import (
      File "c:\users\leo\anaconda3\envs\spyder-env\lib\site-packages\coursera\cookies.py", line 9, in <module>
        import ssl
      File "c:\users\leo\anaconda3\envs\spyder-env\lib\ssl.py", line 98, in <module>
        import _ssl             # if we can't import it, let the error propagate
    ImportError: DLL load failed while importing _ssl: The specified module could not be found.

Solution

  • this works: Make sure to install Coursera Authentication helper for Firefox and add this to your CAUTH (I noticed this sequence changes everyday and has to be updated in the coursera-dl.conf), login Coursera and you should be ready to download all the classes you wish! Make sure to go to the classe's link when part of a specialisation.

    If you need more help, you can read my journey below:

    EDIT

    This has worked for many classes so far and I am not getting any errors. Using Anaconda 3 command promt. Here is what I did:

    In environment variables, I added new paths, stated from this post https://stackoverflow.com/a/54897379/16367595

     D:\Anaconda3 
    D:\Anaconda3\Scripts
    D:\Anaconda3\Library\bin 
    

    Make sure to check what yours looks like, mine was in the C: drive, for instance.

    Then I reinstalled:

    python -m pip install coursera-dl
    

    AND INTERESTINGLY this has actually only worked for 1 course, i.e. learn to write for screenplay etc initially. I then tried it again when I was getting the error below for another class, and it worked.

    AttributeError: 'HTMLParser' object has no attribute 'unescape'
    

    The following day, I was getting this error for other classes:

    403 client error, Forbidden for URL
    

    So finally, I made sure I was logged in in all of my browsers (not sure if this contributed) however, I think the solution to the above error comes from updating the CAUTH section of the coursera-dl.conf file. The successful cases above worked with the Google Chrome CAUTH cookies from coursera.org. The following day worked when I installed the Coursera Authentication extension for Firefox and replaced the older CAUTH with the one provided with the extension.

    This is working well while using anaconda3 prompt, getting all desired classes downloaded.