Udemy-dl: AttributeError: 'NoneType' object has no attribute 'group'

Created on 24 Nov 2017  路  20Comments  路  Source: r0oth3x49/udemy-dl

After fetching the newest tarball i run into this error on MacOS with Homebrew. Version before was good, but got in Courses with empty material files (e.g. Empty PowerPoint files) always:

Traceback (most recent call last):
File "udemy-dl.py", line 858, in
main()
File "udemy-dl.py", line 774, in main
udemy.ExtractAndDownload(path=outto)
File "udemy-dl.py", line 387, in ExtractAndDownload
out = self.Downloader(_url, lecture_name, chapter_path)
File "udemy-dl.py", line 88, in Downloader
out = course_dl.download(url, title, filepath=path, quiet=True, callback=self.Download)
File "/Users/shade/Downloads/udemy-dl-master/udemy/_downloader.py", line 120, in download
progress_stats = (bytesdone, bytesdone * 1.0 / total, rate, eta)
ZeroDivisionError: float division by zero

Now, with the newest revision i get:

[] : Downloading webpage..
[
] : Extracting course information..
[*] : Downloading '....'.
Traceback (most recent call last):
File "udemy-dl.py", line 858, in
main()
File "udemy-dl.py", line 774, in main
udemy.ExtractAndDownload(path=outto)
File "udemy-dl.py", line 280, in ExtractAndDownload
self.login()
File "udemy-dl.py", line 39, in login
extract_info.login(self.username, self.password)
File "/Users/shade/.Trash/udemy-dl-master/udemy/_extractor.py", line 99, in login
csrf_token = self._get_csrf_token()
File "/Users/shade/.Trash/udemy-dl-master/udemy/_extractor.py", line 70, in _get_csrf_token
return match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Irrelevant invalid

Most helpful comment

pip install pyOpenSSL

All 20 comments

@Shadesh thanks for the report. can you please explain a bit more. like which command you have used and the course URL you are trying to download?i 'm trying to reproduce this error so that i can fix it ASAP. according to error the code might unable to get the login form data. i just tested the latest version on Mac with this course The Web Developer Bootcamp and it works fine for me. i will be waiting for more details from you.

@r0oth3x49 Im using this CLI command:
python2 udemy-dl.py -u [email protected] -p SecretPW https://www.udemy.com/cisco-ccnp-switch-300-115-the-complete-course/ -d -o /Users/shade/Downloads/

The original error is back now, i updated some Homebrew Python modules and the first error (AttributeError: 'NoneType' object has no attribute 'group') is gone. Now im still running into the problem with 0 Byte files from udemy.com:

[] : Downloading lecture : (5 of 14)
[
] : Downloading (042 IEEE 802_1d Overview-subtitle-en.vtt)
[*] : Lecture : '042 IEEE 802_1d Overview-subtitle-en.vtt' (already downloaded).

[] : Downloading lecture : (6 of 14)
[
] : Downloading (042 S7L33-IEEE-802.1D-Overview.pptx)
Traceback (most recent call last):
File "udemy-dl.py", line 893, in
main()
File "udemy-dl.py", line 809, in main
udemy.ExtractAndDownload(path=outto)
File "udemy-dl.py", line 391, in ExtractAndDownload
out = self.Downloader(_url, lecture_name, chapter_path)
File "udemy-dl.py", line 88, in Downloader
out = course_dl.download(url, title, filepath=path, quiet=True, callback=self.Download)
File "/Users/shade/Downloads/udemy-dl-master/udemy/_downloader.py", line 115, in download
eta = (total - bytesdone) / (rate * 1024)
ZeroDivisionError: float division by zero

The files have 0 byte size on the udemy.com website, maybe the teacher had a bad upload or something. It would be nice if your downloader can skip those broken files :)

@Shadesh i will add a handle for this error ASAP.

@Shadesh i have updated the code you can check it now.

Thanks but the "ZeroDivisionError" error is still there:

[] : Downloading lecture : (3 of 14)
[
] : Downloading (041 S7L32-Intro-to-Traditional-STP.pptx)
Traceback (most recent call last):
File "udemy-dl.py", line 893, in
main()
File "udemy-dl.py", line 809, in main
udemy.ExtractAndDownload(path=outto)
File "udemy-dl.py", line 391, in ExtractAndDownload
out = self.Downloader(_url, lecture_name, chapter_path)
File "udemy-dl.py", line 88, in Downloader
out = course_dl.download(url, title, filepath=path, quiet=True, callback=self.Download)
File "/Users/shade/.Trash/udemy-dl-master/udemy/_downloader.py", line 115, in download
eta = (total - bytesdone) / (rate * 1024)
ZeroDivisionError: float division by zero

Hi, any new about the ZeroDivisionError error?
Thanks a lot for your work!

@Shadesh i cannot reproduce the error so i am adding a temporary fix, let me if that fix works for you ASAP.

@r0oth3x49 Thanks for it but unfortunately it doesnt seem to work. The error si gone but it just stops forever where it failed before.

@Shadesh sorry for that. i will add another fix ASAP if some how i 'm able to reproduce the error. 'm not registered in the course you are downloading that's why i cannot test against that course.

I got it fixed by myself but only with the ugliest hack 2017 (For me at least).
I commented out everything related to the progress bar and calculating the size, now i dont have a progress bar but everything is downloading.

If interested, thats what i did in your _downloader.py file

       while self._active:
            chunk = response.read(chunksize)
            outfh.write(chunk)
            elapsed = time.time() - t0
            bytesdone += len(chunk)
            if elapsed:
             #   rate = ((float(bytesdone) - float(offset)) / 1024.0) / elapsed
              #  eta  = (total - bytesdone) / (rate * 1024.0)
            #else:
                rate = 0
                eta = 0
            #progress_stats = (bytesdone, bytesdone * 1.0 / total, rate, eta)
            progress_stats = 0
            if not chunk:
                outfh.close()
                break
            if not quiet:
                status = status_string.format(*progress_stats)
                sys.stdout.write("\r" + status + ' ' * 4 + "\r")
                sys.stdout.flush()
            #if callback:
             #   callback(total, *progress_stats)

As is said, i'm not a programmer.... ;)

@Shadesh i have another fix for you which is quite good than this. just create file with same name in the directory it will not download that file again if exists this is pretty funny fix but it will work for you.
let say this file 041 S7L32-Intro-to-Traditional-STP.pptx is disturbing your download you create this file in chapter's directory and udemy-dl wont download it again if its already available.

when I run this command
python -m udemy_dl -s https://www.udemy.com/the-web-developer-bootcamp

I get the following error : -

Traceback (most recent call last):
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 97, in get_csrf_token
return match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:Python\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:Python\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:Python\lib\site-packages\udemy_dl__main__.py", line 8, in
main()
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 837, in main
udemy_dl(username, password, link, lecture_start, lecture_end, save_links, safe_file_names, just_list, output_dest)
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 658, in udemy_dl
login(username, password)
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 109, in login
csrf_token = get_csrf_token()
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 102, in get_csrf_token
return match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Any fix for this?

On Ubuntu Linux 16.04
I can confirm the same error
[INFO-133] Trying to log in ...
[ERROR-61] Exception
Traceback (most recent call last):
File "/usr/local/bin/udemy-dl", line 7, in
main()
File "/usr/local/lib/python2.7/dist-packages/udemy_dl/udemy_dl.py", line 947, in main
save_links, safe_file_names, just_list, output_dest, dir_use_course_title)
File "/usr/local/lib/python2.7/dist-packages/udemy_dl/udemy_dl.py", line 744, in udemy_dl
login(username, password)
File "/usr/local/lib/python2.7/dist-packages/udemy_dl/udemy_dl.py", line 134, in login
csrf_token = get_csrf_token()
File "/usr/local/lib/python2.7/dist-packages/udemy_dl/udemy_dl.py", line 128, in get_csrf_token
return match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Same problem here in Windows 7 - there is an exception before login.Same happened when tried to download 2 courses.Here is the error message :

Trying to log in ...
Exception
Traceback (most recent call last):
File "udemy_dl.py", line 976, in module ( note: the word module inside <> )
File "udemy_dl.py", line 971, in main
File "udemy_dl.py", line 766, in udemy_dl
File "udemy_dl.py", line 156, in login
File "udemy_dl.py", line 150, in get_csrf_token
AttributeError: 'NoneType' object has no attribute 'group'
Failed to execute script udemy_dl

Same error here on ElementaryOS (Ubuntu based distro):
$ udemy-dl -u user@domain -p * https://www.udemy.com/course
[INFO-835] Downloading to: /home/username/PATH

[INFO-107] Trying to log in ...
Traceback (most recent call last):
File "/usr/local/bin/udemy-dl", line 7, in
main()
File "/usr/local/lib/python2.7/dist-packages/udemy_dl/udemy_dl.py", line 837, in main
udemy_dl(username, password, link, lecture_start, lecture_end, save_links, safe_file_names, just_list, output_dest)
File "/usr/local/lib/python2.7/dist-packages/udemy_dl/udemy_dl.py", line 658, in udemy_dl
login(username, password)
File "/usr/local/lib/python2.7/dist-packages/udemy_dl/udemy_dl.py", line 109, in login
csrf_token = get_csrf_token()
File "/usr/local/lib/python2.7/dist-packages/udemy_dl/udemy_dl.py", line 102, in get_csrf_token
return match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

pip install pyOpenSSL

The issue is that if you keep on trying the udemy-dl script in a short period of time, udemy blocks you and @r0oth3x49 's regex to fetch csrf token fails.

Retry after pausing and this issue won't affect you

I am getting below error on macOS Sierra.can someone help me out. i tried every possible solution like upgrading the ssl and all but no luck.

[INFO-835] Downloading to: /Users/rk185269/java-the-complete-java-developer-course

[INFO-107] Trying to log in ...
Traceback (most recent call last):
File "/usr/local/bin/udemy-dl", line 7, in
main()
File "/Library/Python/2.7/site-packages/udemy_dl/udemy_dl.py", line 837, in main
udemy_dl(username, password, link, lecture_start, lecture_end, save_links, safe_file_names, just_list, output_dest)
File "/Library/Python/2.7/site-packages/udemy_dl/udemy_dl.py", line 658, in udemy_dl
login(username, password)
File "/Library/Python/2.7/site-packages/udemy_dl/udemy_dl.py", line 109, in login
csrf_token = get_csrf_token()
File "/Library/Python/2.7/site-packages/udemy_dl/udemy_dl.py", line 95, in get_csrf_token
response = session.get('https://www.udemy.com/join/login-popup')
File "/Library/Python/2.7/site-packages/udemy_dl/udemy_dl.py", line 66, in get
return self.session.get(url, headers=self.headers)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 521, in get
return self.request('GET', url, *kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, *
send_kwargs)
File "/Library/Python/2.7/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/Library/Python/2.7/site-packages/requests/adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.udemy.com', port=443): Max retries exceeded with url: /join/login-popup (Caused by SSLError(SSLError(1, u'[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)'),))

when I run this command
python -m udemy_dl -s https://www.udemy.com/the-web-developer-bootcamp

I get the following error : -

Traceback (most recent call last):
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 97, in get_csrf_token
return match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:Python\lib\runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "C:Python\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:Python\lib\site-packages\udemy_dl__main__.py", line 8, in
main()
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 837, in main
udemy_dl(username, password, link, lecture_start, lecture_end, save_links, safe_file_names, just_list, output_dest)
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 658, in udemy_dl
login(username, password)
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 109, in login
csrf_token = get_csrf_token()
File "C:Python\lib\site-packages\udemy_dl\udemy_dl.py", line 102, in get_csrf_token
return match.group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Any fix for this?

Did anyone find a fix for this?

This error does not belongs to this repository as there is no such function which fetches csrf_token, and this repo cannot be installed via PIP so better clone/download it from here and use, and if still facing some kind of error let me know or create new issue by following issue reporting guideline.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Carlosx7 picture Carlosx7  路  9Comments

Puyodead1 picture Puyodead1  路  8Comments

pppedrillo picture pppedrillo  路  10Comments

TechieGenie picture TechieGenie  路  10Comments

mumi picture mumi  路  10Comments