liranbg / linkedin-learning-downloader

Linkedin Learning videos downloader
202 stars 105 forks source link

Error running #43

Open Johanndut opened 4 years ago

Johanndut commented 4 years ago

When running the python linkedin_learning.py i get the errors : 2020-05-06 13:09:02,102 asyncio DEBUG Using proactor: IocpProactor 2020-05-06 13:09:02,107 root INFO [] -------------Login------------- 2020-05-06 13:09:02,108 root INFO [] Login step 1 - Getting CSRF token... Traceback (most recent call last): File "linkedin_learning.py", line 234, in loop.run_until_complete(process()) File "C:\Python38\lib\asyncio\base_events.py", line 616, in run_until_complete return future.result() File "linkedin_learning.py", line 218, in process await login(USERNAME, PASSWORD) File "linkedin_learning.py", line 82, in login csrf = html.xpath("//input[@name='loginCsrfParam']/@value").pop() IndexError: pop from empty list

I am not using a proxy

Plueki commented 4 years ago

Same issue here! Please fix this! Happened on Python 3.7 and 3.8

File "linkedin_learning.py", line 218, in process await login(USERNAME, PASSWORD) File "linkedin_learning.py", line 82, in login csrf = html.xpath("//input[@name='loginCsrfParam']/@value").pop() IndexError: pop from empty list

hamoudaalias commented 4 years ago

same problem here. cant get loginCsrfParam value please help

kevinrodriguez-io commented 4 years ago

Same issue

slotbite commented 4 years ago

Mismo error alguien tiene una ejemplo del parámetro ?

hamoudaalias commented 4 years ago

CsrfParam value not passed in body but is in cookie bcookie = v=2&ec3a7c1b-0487-41af-8a6b-3f6aa2302a30 just delete v=2& and CsrfParam = ec3a7c1b-0487-41af-8a6b-3f6aa2302a30 this data found in resp jute after resp = await session.get(URL, proxy=PROXY) but im not good developper for extract it can you help ?

hamoudaalias commented 4 years ago

Hello, first of all I don't speak English so this discussion is an automatic translation (not by Google translate) but with https://www.deepl.com/ (long live of artificial intelligence and deeplearning) Second thing, I'm not a coder or a developer but I'm a good handyman and I'm happy to break things and fix them afterwards :) I created this code with my feet to get the CsrfParam surely there are 1000 ways to do it cleanly and I don't know how to do it, but I did it anyway. I know it's too rotten code but I can't do better the important thing for me that it runs and that it works and yes I resume downloading lessons :)

If someone is kind enough to rewrite what I wrote properly and send me what he did so that I don't do stupid things next time it'll be too kind.

So for the code to work as usual just replace the "async def login(username, password)" function with this code. `async def login(username, password): async with aiohttp.ClientSession(headers=HEADERS, cookie_jar=COOKIE_JAR) as session: logging.info("[*] Login step 1 - Getting CSRF token...") resp = await session.get(URL, proxy=PROXY)

    print("-----hamouddda--------------------------")               
    b=resp.cookies.output(attrs=[],header="Cookie:") 

    lignes = b.split("\n")
    for l in lignes:
        pos1=l.find('bcookie="v=2&')
        if pos1>-1:

            b=l.split('"')[1]
            b=b.split('v=2&')[1]

    body = await resp.text()

    csrf = b
    logging.debug(f"[*] CSRF: {csrf}")
    data = {
        "session_key": username,
        "session_password": password,
        "loginCsrfParam": csrf,
        "isJsEnabled": False
    }
    logging.info("[*] Login step 1 - Done")
    logging.info("[*] Login step 2 - Logging In...")
    await session.post(urljoin(URL, 'uas/login-submit'), proxy=PROXY, data=data)

    if not next((x.value for x in session.cookie_jar if x.key.lower() == 'li_at'), False):
        raise RuntimeError("[!] Could not login. Please check your credentials")

    HEADERS['Csrf-Token'] = next(x.value for x in session.cookie_jar if x.key.lower() == 'jsessionid')
    logging.info("[*] Login step 2 - Done")
    `

good download to all and do not forget if you managed to optimize what I did do do not hesitate to contact me.

slotbite commented 4 years ago

Thank you @hamoudaalias very much this corrects the error by CSRF for now!

maximx86 commented 4 years ago

After replacing the code I am getting an error: RuntimeError: Session is closed

Could you help please? I don't know much about programming. Thank you,

f:\linkedin learning\downloader>python linkedin_learning.py 2020-05-30 17:04:21,536 asyncio DEBUG Using proactor: IocpProactor 2020-05-30 17:04:21,539 root INFO [] -------------Login------------- 2020-05-30 17:04:21,539 root INFO [] Login step 1 - Getting CSRF token... 2020-05-30 17:04:21,946 root DEBUG [] CSRF: 7c46fa40-20a1-4155-8aad-91f2156d74b2 2020-05-30 17:04:21,946 root INFO [] Login step 1 - Done 2020-05-30 17:04:21,947 root INFO [*] Login step 2 - Logging In... Traceback (most recent call last): File "linkedin_learning.py", line 244, in loop.run_until_complete(process()) File "c:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 616, in run_until_complete return future.result() File "linkedin_learning.py", line 228, in process await login(USERNAME, PASSWORD) File "linkedin_learning.py", line 102, in login await session.post(urljoin(URL, 'uas/login-submit'), proxy=PROXY, data=data) File "c:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\aiohttp\client.py", line 357, in _request raise RuntimeError('Session is closed') RuntimeError: Session is closed