2
import wget

for link in saved:
    url = link.url
    wget.download(url,'downloads/')

This code works however it fails and stops soon as the first error occurs, as I don't filter or test whats in link.url as that gets populated from another function. How do I ignore any errors wget receives so it can continue on. I don't care but if possible, errors can be appended to the local file system this is running from in a file called error.

Thank you for any assistance. I am still very new to Python.

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
Jon Weinraub
  • 397
  • 1
  • 8
  • 18
  • 1
    Possible duplicate of [How to properly ignore exceptions](https://stackoverflow.com/questions/730764/how-to-properly-ignore-exceptions) – r.ook Feb 21 '19 at 20:58

1 Answers1

5

Just wrap a try/except around the wget call - in the except code you'll have access to the exception object representing the problem that occurred. you can do whatever you want with the information in that object. logging it somewhere is the most usual thing to do if you're going to otherwise ignore it. (A golden rule of programming is to never completely ignore an error):

import wget

for link in saved:
    url = link.url
    try:
        wget.download(url,'downloads/')
    except Exception as ex:  # could catch a more specific Exception object
        # log the exception here
CryptoFool
  • 21,719
  • 5
  • 26
  • 44
  • I was about to post something very similar to this. (upvoted) – Luke Brady Feb 21 '19 at 21:05
  • Ah, I think one of my functions is actually bailing out, `, line 41, in __getattr__ .format(self.__class__.__name__, attribute))` is when it bails, because it everntually failed. The download log I made is being populated though, `Failed to download bl00p: need more than 1 value to unpack` – Jon Weinraub Feb 21 '19 at 21:58
  • Sounds like we've moved you along some. Your last comment doesn't provide enough information for me to do anything with it. Feel free to add to your post with more information and questions...or start a new question if you're experiencing a completely different issue. – CryptoFool Feb 22 '19 at 00:22
  • Yes I think a new question will probably be better after I futz around with this some more, thank you! – Jon Weinraub Feb 22 '19 at 14:39