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

error if deskshare.webm is missing somehow #2

Open
P-D- opened this issue Nov 12, 2020 · 2 comments
Open

error if deskshare.webm is missing somehow #2

P-D- opened this issue Nov 12, 2020 · 2 comments

Comments

@P-D-
Copy link

P-D- commented Nov 12, 2020

I handled this one my self, adding a try:catch block (thanks stackoverflow https://stackoverflow.com/questions/16778435/python-check-if-website-exists)

-            resp = urllib.request.urlopen(req)
-            content_length = resp.headers['Content-Length']
-            if content_length is not None: content_length = int(content_length)
-            while True:
-                with resp:
-                    n = resp.readinto(buf)
-                    while n > 0:
-                        fp.write(buf[:n])
-                        n = resp.readinto(buf)
-                current = fp.seek(0, os.SEEK_CUR)
-                if content_length is None or current >= content_length:
-                    break
-                print("continuing...")
-                req = urllib.request.Request(url)
-                req.add_header('User-Agent', 'bbb-video-downloader/1.0')
-                req.add_header('Range', f'bytes={current}-')
+            try:
+                resp = urllib.request.urlopen(req)
+            except urllib.error.HTTPError as e:
+                # Return code error (e.g. 404, 501, ...)
+                # ...
+                print('HTTPError: {}'.format(e.code))
+            except urllib.error.URLError as e:
+                # Not an HTTP-specific error (e.g. connection refused)
+                # ...
+                print('URLError: {}'.format(e.reason))
+            else:
+                content_length = resp.headers['Content-Length']
+                if content_length is not None: content_length = int(content_length)
+                while True:
+                    with resp:
+                        n = resp.readinto(buf)
+                        while n > 0:
+                            fp.write(buf[:n])
+                            n = resp.readinto(buf)
+                    current = fp.seek(0, os.SEEK_CUR)
+                    if content_length is None or current >= content_length:
+                        break
+                    print("continuing...")
+                    req = urllib.request.Request(url)
+                    req.add_header('User-Agent', 'bbb-video-downloader/1.0')
+                    req.add_header('Range', f'bytes={current}-')
+                    resp = urllib.request.urlopen(req)
@smimram
Copy link

smimram commented Feb 3, 2021

FWIW, I just ran into this one too, it would be nice if some patch could be merged!

@Zorlin
Copy link

Zorlin commented Feb 3, 2021 via email

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

3 participants