r0oth3x49 / udemy-dl

A cross-platform python based utility to download courses from udemy for personal offline use.
MIT License
4.86k stars 1.2k forks source link

UnicodeEncodeError: 'ascii' codec can't encode characters in position 51-52 #13

Closed bharathgrk closed 7 years ago

bharathgrk commented 7 years ago

I'm having an issue while downloading the course iOS 11 & Swift 4 - The Complete iOS App Development Bootcamp. The download stopped with the following error message:

Traceback (most recent call last): File "udemy-dl.py", line 646, in main() File "udemy-dl.py", line 496, in main udemy.ExtractAndDownload(path=outto, quality=res, default=True) File "udemy-dl.py", line 356, in ExtractAndDownload f.write("[+] -- name {}\n[+] -- Visit {}\n".format(lecture_name, _url)) UnicodeEncodeError: 'ascii' codec can't encode characters in position 51-52: ordinal not in range(128)

Running on python version 2.7.14 and macOS Sierra 10.12.6

Can you please look into it?

r0oth3x49 commented 7 years ago

@bharathgrk thanks for trying this out. first of all can you please make sure you have an updated repo of udemy-dl and then try again the same course and post the Screenshot here. currently i don't have macOS Sierra i 'm using macOS Mavericks on which i have already tested and it works fine. BTW sorry for the late response. i will soon update the repo.

KK7NZY commented 7 years ago

Running into similar issue on macOS Sierra 10.13 in python:2.7.14 docker container. Was trying to download ethereum-dapp course at 720p.

[*] : Saving external links to file : links-to-visit.txt
Traceback (most recent call last):
  File "udemy-dl.py", line 646, in <module>
    main()
  File "udemy-dl.py", line 614, in main
    udemy.ExtractAndDownload(path=outto, quality=res)
  File "udemy-dl.py", line 356, in ExtractAndDownload
    f.write("[+] -- name {}\n[+] -- Visit {}\n".format(lecture_name, _url))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 35-36: ordinal not in range(128)
bharathgrk commented 7 years ago

Cloned the repo using the git clone command in your readme file and tried the download again with the same result. Attaching the screenshot below. Thanks for responding.

screen shot 2017-10-31 at 12 21 01

selanium commented 7 years ago
diff --git a/udemy-dl.py b/udemy-dl.py
index cd9af9a..4ce9258 100644
--- a/udemy-dl.py
+++ b/udemy-dl.py
@@ -353,7 +353,7 @@ class UdemyDownload:
                         _external_links = "links-to-visit.txt"
                         print (fc + sd + "\n[" + fm + sb + "*" + fc + sd + "] : " + fg + sd + "Saving external links to file : {}".format(_external_links))
                         f = open(_external_links, "a")
-                        f.write("[+] -- name {}\n[+] -- Visit {}\n".format(lecture_name, _url))
+                        f.write("[+] -- name {}\n[+] -- Visit {}\n".format(lecture_name, _url.encode("utf-8").strip()))
                         f.close()
                         print (fc + sd + "[" + fm + sb + "*" + fc + sd + "] : " + fg + sd + "Saved successfully..")
                     elif _url:

@@ -173,7 +173,7 @@ class UdemyDownload:

                    if _url:
                        with open("%s.txt" % (course), "a") as f:
-                           f.write("[+] -- name : %s\n[+] -- link : %s\n" % (lecture_name, _url))
+                           f.write("[+] -- name : %s\n[+] -- link : %s\n" % (lecture_name, _url.encode("utf-8").strip()))
                            f.close()
            print (fc + sd + "[" + fm + sb + "+" + fc + sd + "] : " + fg + sd + "Saved successfully.")

here is the solution of the problem. note : I tested this and works well it can be merged

r0oth3x49 commented 7 years ago

@bharathgrk as i said i 'm working on new release which has the patch for this error as well. sorry for the late response.

selanium commented 7 years ago

sorry @r0oth3x49 can we speak in another place? like skype or telegram or yahoo. thanks

r0oth3x49 commented 7 years ago

@selanium you can add me on fb. r0oth3x49

r0oth3x49 commented 7 years ago

@bharathgrk issue is fixed now in new version.

bharathgrk commented 7 years ago

@r0oth3x49 new version worked like a charm, thanks for the fix.