Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Did not find necessary cookies' output when trying to download courses #547

Closed
rolfmorel opened this issue Jul 1, 2016 · 43 comments
Closed

Comments

@rolfmorel
Copy link

rolfmorel commented Jul 1, 2016

Subject of the issue

coursera-dl does not seem to authenticate through cookies correctly and always exits with the message: Could not authenticate: Did not find necessary cookies.

I tried it for a number of course names: sdn1, sdn1-001, modelthinking, modelthinking-004, and the one I am currently interested in: crypto, for which I also tried learn/crypto.

Your environment

  • Operating System (name/version): ArchLinux, Linux 4.6.2
  • Python version: 3.5.1
  • coursera-dl version: latest checkout 0.6.1 with commit 81b9d40 (also tried release version 0.6.1)

Steps to reproduce

Tell us how to reproduce this issue, please don't forget to include
enough information so that you can help us help you:

  • Is the problem happening with the latest version of the script?

    • yes, checkout of the current repo at commit 81b9d40
  • Do you have all the recommended versions of the modules? See them in the
    file requirements.txt.

    • Performed sudo pip install -r requirements.txt --upgrade on the repo checkout.
  • What is the course that you are trying to access?

  • What is the precise command line that you are using.

    • coursera-dl -u 'username@gmail.com' -p 'XXXXXXX' crypto
    • coursera-dl -u 'username@gmail.com' -p 'XXXXXXX' learn/crypto
    • Note: I tried the --on-demand command switch, but this only outputs a depreciated option message extra.
  • What are the precise messages that you get? Please, use the --debug
    option before posting the messages as a bug report. Please, copy and paste
    them. Don't reword/paraphrase the messages.

    $ coursera-dl -u 'username@gmail.com' -p 'XXXXXXX' crypto --debug
    root[main] coursera_dl version 0.6.1
    root[main] Downloading class: crypto
    root[download_class] Downloading old style class crypto
    root[get_cookies_from_cache] Trying to get cookies from the cache.
    root[load_cookies_file] Loading cookie file /tmp/rolf_coursera_dl_cache/cookies/rolfmorel@gmail.com.txt into memory.
    root[get_cookies_from_cache] Could not load cookies from the cache.
    root[login] Initiating login.
    root[login] There were no .coursera.org cookies to be cleared.
    requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): class.coursera.org
    requests.packages.urllib3.connectionpool[_make_request] "GET /crypto HTTP/1.1" 200 None
    root[login] Forging cookie header: csrftoken=5jeRB9VL13vGBq5QZ; csrf2_token_oiH1R=____D0VB0Q2I3POZciw6Woio.
    requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): www.coursera.org
    requests.packages.urllib3.connectionpool[_make_request] "POST /api/login/v3 HTTP/1.1" 200 None
    root[login] Logged in on coursera.org.
    requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): class.coursera.org
    requests.packages.urllib3.connectionpool[_make_request] "GET /crypto/auth/auth_redirector?type=login&subtype=normal HTTP/1.1" 200 None
    root[down_the_wabbit_hole] Following https://class.coursera.org/crypto/auth/auth_redirector?type=login&subtype=normal to authenticate on class.coursera.org.
    root[down_the_wabbit_hole] Exiting "deep" authentication.
    root[main] Could not authenticate: Did not find necessary cookies.

Expected behaviour

Having used coursera-dl some time ago, I expected it to download the course.

Actual behaviour

If I run the command coursera-dl -u 'username@gmail.com' -p 'XXXXXXX' crypto , or with any other course name, the output that I get back is as follows:

coursera_dl version 0.6.1
Downloading class: crypto
Starting new HTTPS connection (1): class.coursera.org
Starting new HTTPS connection (1): www.coursera.org
Logged in on coursera.org.
Starting new HTTPS connection (1): class.coursera.org
Could not authenticate: Did not find necessary cookies.
@balta2ar
Copy link
Member

balta2ar commented Jul 1, 2016

@Polyphemus This is a known issue. Please see this: #508 (comment)

@rolfmorel
Copy link
Author

Thank you, forcing the call to be to download_on_demand_class(...) instead of download_old_style_class(...) did indeed work.

@tourist-py
Copy link

I think the same error(#154) got the different reason.

@jaidevd
Copy link

jaidevd commented Jul 2, 2016

Thanks, @Polyphemus for raising this issue, I too started seeing this only today. Thanks, @balta2ar , your suggestion works.

@oliyiyi
Copy link

oliyiyi commented Jul 2, 2016

Thanks, I got it.

@jiangtiandao
Copy link

jiangtiandao commented Jul 2, 2016

https://github.com/coursera-dl/coursera-dl/blob/master/coursera/coursera_dl.py#L1320

@befreshdumbie
Copy link

Thank @jiangtiandao , your code line worked for me

@shkp
Copy link

shkp commented Jul 2, 2016

I am having the same issue. I was able to download courses just fine, till yesterday, today I'm seeing this error. I have seen all the older threads and successfully updated both the script and the requirements. However, I could not quite figure out how to use --clear-cache and also the solutions posted on this thread (how can I change and access sections of the script).

I am relatively, a noob, when it comes to programming. In fact, this is exactly what I'm trying to get better at through Coursera. I hope you guys can help me out. Thanks in advance. And thanks to the makers of this project for helping all of us learn new things.

@balta2ar
Copy link
Member

balta2ar commented Jul 2, 2016

@shk3 What courses are you downloading? Old courses were shut down yesterday, only on-demand courses are available now.

@shkp
Copy link

shkp commented Jul 3, 2016

@balta2ar I believe the course i was trying to download was an on-demand course. It was Front-end Javascript Frameworks: Angular JS. The error, as i mentioned above is "Could not authenticate: Did not find necessary cookies."

C:\Users\shkp\venv1\Scripts>coursera-dl -u user@gmail.com -p XXXXXXX angular-js --debug root[main] coursera_dl version 0.6.1 root[main] Downloading class: angular-js root[download_class] Downloading old style class angular-js root[get_cookies_from_cache] Trying to get cookies from the cache. root[load_cookies_file] Loading cookie file C:\Windows\TEMP\shkp_coursera_dl_cache\cookies\user@gmail.com.txt into memory. root[get_cookies_from_cache] Could not load cookies from the cache. root[login] Initiating login. root[login] There were no .coursera.org cookies to be cleared. requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): class.coursera.org requests.packages.urllib3.connectionpool[_make_request] "GET /angular-js HTTP/1.1" 200 None root[login] Forging cookie header: csrftoken=QmCbpWk31D6qbQi6SsI5; csrf2_token_Q9Aedfcj=A4OttJdduuvDVjn3N2g3SY8I. requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): www.coursera.org requests.packages.urllib3.connectionpool[_make_request] "POST /api/login/v3 HTTP/1.1" 200 None root[login] Logged in on coursera.org. requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): class.coursera.org requests.packages.urllib3.connectionpool[_make_request] "GET /angular-js/auth/auth_redirector?type=login&subtype=normal HTTP/1.1" 200 None root[down_the_wabbit_hole] Following https://class.coursera.org/angular-js/auth/auth_redirector?type=login&subtype=norma l to authenticate on class.coursera.org. root[down_the_wabbit_hole] Exiting "deep" authentication. root[main] Could not authenticate: Did not find necessary cookies.

I do see that when i use the --debug attribute that it is trying to download the course as an 'old style course'. But I'm not sure what the solution is, to that. I also, still cannot figure out how to use the --clear-cache attribute.coursera-dl -u <user> -p <pass> angular-js --clear-cache gives me an error saying NameError: name 'download_class' is not defined. I installed this using pip in a virtualenv. Any help is appreciated. Thanks in advance.

@balta2ar
Copy link
Member

balta2ar commented Jul 3, 2016

@shkp Confirming. Old classes do not work anymore and unfortunately because of that downloader fails to switch to on-demand class download. You need to hack the code. See my comment above in this issue. We will fix it in the next version.

@shk3
Copy link
Member

shk3 commented Jul 3, 2016

@balta2ar I guess you meant to mention @shkp right? I am not actively using the downloader for a while.

@balta2ar
Copy link
Member

balta2ar commented Jul 4, 2016

Yes, sorry! Github completion confused me.

@l1th1um
Copy link

l1th1um commented Jul 5, 2016

In the newest version, I'm switching the exception in download_class function. So it will try the new version first, then the old version

try:
    logging.debug('Downloading new style (on demand) class %s', class_name)
        return download_on_demand_class(args, class_name)           
except ClassNotFound:
    logging.debug('Downloading old style class %s', class_name)
        return download_old_style_class(args, class_name)

@simratsingh96
Copy link

simratsingh96 commented Jul 5, 2016

@balta2ar I am getting the same error inspite of changing all occurrences of 'download_class' to 'download_on_demand_class'.

@balta2ar
Copy link
Member

balta2ar commented Jul 5, 2016

@simratsingh96 Which course?

@simratsingh96
Copy link

https://www.coursera.org/learn/probability-intro/home : Introduction to Probability and Data

@balta2ar
Copy link
Member

balta2ar commented Jul 5, 2016

@simratsingh96 Could you use the latest version from github? Support for old courses is already removed there, I think it should work for you. This change will be in the next release.

@simratsingh96
Copy link

@balta2ar I am using the most recent version 0.6.1

@balta2ar
Copy link
Member

balta2ar commented Jul 5, 2016

@simratsingh96 The changes that I'm talking about are not yet tagged, they are not in pip yet. Follow this: https://github.com/coursera-dl/coursera-dl#alternative-installation-method-for-unix-systems

@simratsingh96
Copy link

@balta2ar I use a mac, the instructions seem to be for a windows environment. Are there terminal specefic instructions availible?

@balta2ar
Copy link
Member

balta2ar commented Jul 5, 2016

@simratsingh96 they work for mac

@simratsingh96
Copy link

Thank you for the suggestions @balta2ar. Worked perfectly for me

@edoardovivo
Copy link

Thank you @balta2ar ! Works fine now!

@samrus98
Copy link

@balta2ar, I am not able to make it work.
I have Python 3.5 and I have already reinstalled and upgraded coursera-dl. After that I located the coursera-dl.py file at path C:\Users\AppData\Local\Programs\Python\Python35\Lib\site-packages\coursera and replaced download_class to download_on_demand_class but I am still getting the error as follows:
error_

I tried downloading the following courses:

  1. https://www.coursera.org/learn/ml-recommenders
  2. https://www.coursera.org/learn/marketing-digital

Alternatively when I tried to use the coursera-dl.py file you pointed to in post https://github.com/coursera-dl/coursera-dl/blob/master/coursera/coursera_dl.py#L1293 after making the same replacement, I am getting the error as shown below:
error

Please let me know what I should do differently?

-Sam

@balta2ar
Copy link
Member

balta2ar commented Jul 14, 2016

@samrus98 Have you tried this instruction? https://github.com/coursera-dl/coursera-dl#alternative-installation-method-for-unix-systems Pay attention that this instruction does not use pip to install coursera-dl (only for dependencies).

@samrus98
Copy link

@balta2ar I am currently trying to do this in Windows command prompt...are you indicating that I should use unix environment? I am assuming that you are talking about the following piece of code:

cd /directory/where/I/want/my/courses
virtualenv my-coursera
cd my-coursera
source bin/activate
git clone https://github.com/coursera-dl/coursera-dl
cd coursera
pip install -r requirements.txt
./coursera-dl ...

@balta2ar
Copy link
Member

Well, in Windows you can do pretty much the same. I think there is git for windows, so it's possible. In fact, you don't necessarily need to clone, you can simply download master.zip and unpack it. I think virtualenv should work for Windows too.

@neokito
Copy link

neokito commented Jul 15, 2016

I have the same problem :/

course: https://www.coursera.org/learn/climate-change-mitigation/home/week/1

screenshot 2016-07-15 18 20 15

screenshot 2016-07-15 18 20 09

@zjfjyc
Copy link

zjfjyc commented Jul 17, 2016

@balta2ar Sorry to disturb you, I have met the same problem as others. I installed the latest version 0.6.1, and tried to fix this problem as what you said in this issue, but it still doesn‘t work on my win 10 laptop.
2016-07-17 13 55 53

@kinshuk4
Copy link

Thanks @balta2ar your suggestion for replacing download_class to download_on_demand_class in main() method worked 👍

@ee7klt
Copy link

ee7klt commented Jul 19, 2016

in which directory do you find coursera-dl.py after installation?

@balta2ar
Copy link
Member

That depends on a lot of things: your OS, installation method, Python version.

@samrus98
Copy link

Unfortunately i could not make the suggested solution work (yet). When are
you planning to release an update?

-Sam

On Jul 14, 2016 14:18, "Yuri Bochkarev" notifications@github.com wrote:

Well, in Windows you can do pretty much the same. I think there is git for
windows, so it's possible. In fact, you don't necessarily need to clone,
you can simply download master.zip and unpack it. I think virtualenv should
work for Windows too.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#547 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AKYCS3ijC-0WKAKqCrQnqLLn-7ci3vslks5qVqeNgaJpZM4JDaSL
.

@balta2ar
Copy link
Member

Only one thing is left in my plans for the next release: quiz download. I've started work on it but it appeared slightly more complicated than I anticipated. I don't want to give any concrete deadlines but I hope to finish it soon.

@whyfuture
Copy link

@balta2ar QUIZ-download would make this insanely cool.

@ghost
Copy link

ghost commented Jul 21, 2016

@balta2ar Thank you! Alternative install working properly.
Debian 8.5.0 and Python 2.7.9.

@tlatforlz
Copy link

@kinshuk4 how you can fix that? you fix in main() function or down_load function?

@caselmer
Copy link

As line numbers have changed:
In which line am I supposed to replace "download_class" with "download_on_demand_class"?

i) def download_class(args, class_name):
ii) if download_class(args, class_name):
iii) both

thanks

@caselmer
Copy link

OK, I can answer my own question.
Only change line with "if download_class(args, class_name):"
:-)

@abhigenie92
Copy link

abhigenie92 commented Jul 28, 2016

I am getting the same issue. I am using the latest version on pip.

abhishek Algos1 $ coursera-dl -u abhigenie@live.com -p XXXXXX algorithm-design-analysis
coursera_dl version 0.6.1
Downloading class: algorithm-design-analysis
Starting new HTTPS connection (1): class.coursera.org
Starting new HTTPS connection (1): www.coursera.org
Logged in on coursera.org.
Starting new HTTPS connection (1): class.coursera.org
Could not authenticate: Did not find necessary cookies.

Debug output:

abhishek Algos1 $ coursera-dl -u abhigenie@live.com -p XXXXXXXXX algorithm-design-analysis-2 --debug
root[main] coursera_dl version 0.6.1
root[main] Downloading class: algorithm-design-analysis-2
root[download_class] Downloading old style class algorithm-design-analysis-2
root[get_cookies_from_cache] Trying to get cookies from the cache.
root[load_cookies_file] Loading cookie file /tmp/abhishek_coursera_dl_cache/cookies/abhigenie@live.com.txt into memory.
root[get_cookies_from_cache] Could not load cookies from the cache.
root[login] Initiating login.
root[login] There were no .coursera.org cookies to be cleared.
requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): class.coursera.org
requests.packages.urllib3.connectionpool[_make_request] "GET /algorithm-design-analysis-2 HTTP/1.1" 200 None
root[login] Forging cookie header: csrftoken=PXVZ5ebBNOiYWf2j29XX; csrf2_token_pEoMCy19=Z4YjKl9Lm3H1tQMpblYzz6eo.
requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): www.coursera.org
requests.packages.urllib3.connectionpool[_make_request] "POST /api/login/v3 HTTP/1.1" 200 None
root[login] Logged in on coursera.org.
requests.packages.urllib3.connectionpool[_new_conn] Starting new HTTPS connection (1): class.coursera.org
requests.packages.urllib3.connectionpool[_make_request] "GET /algorithm-design-analysis-2/auth/auth_redirector?type=login&subtype=normal HTTP/1.1" 200 None
root[down_the_wabbit_hole] Following https://class.coursera.org/algorithm-design-analysis-2/auth/auth_redirector?type=login&subtype=normal to authenticate on class.coursera.org.
root[down_the_wabbit_hole] Exiting "deep" authentication.
root[main] Could not authenticate: Did not find necessary cookies.

Environment:
Kubuntu 16.04 and python3.
Version: 0.6.1. The latest one on coursera-dl github repo.

@caselmer
Copy link

Environment:
Kubuntu 16.04 and python3.
Version: 0.6.1. The latest one on coursera-dl github repo.

I am no expert, but this seems not enough. Inside of my virtual environment I had to edit
./lib/python3.5/site-packages/coursera/coursera_dl.py

Look my previous posts

@balta2ar
Copy link
Member

This should be fixed in 0.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests