0
In my code I run a loop where I download some images of a URL and then save the name of the image in sqlite3
, but after a few inserts
the code simply ignores the line where the insert
.
if hasattr(card, 'image_url'):
print("Downloading card: " + card.name)
card_image = 'images/' + card.set + '/' + card.name + '.jpg'
if not card.image_url == None:
try:
urllib.request.urlretrieve(card.image_url, card_image)
except (HTTPError, URLError) as error:
print('Erro na URL, continuando...')
except timeout:
print('Time out atingido, continuando...')
card_subtype = '|'.join(card.subtypes) if isinstance(card.subtypes, (list)) else card.subtypes
card_color = '|'.join(card.colors) if isinstance(card.colors, (list)) else card.colors
cursor.execute('INSERT INTO cards VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [None, card.name, None, card.multiverse_id, str(card.type), card_subtype, card_color, card.rarity, card.mana_cost, card.power, card.toughness, card.set, card.text, card.flavor, card_image])
print('Saving card: ' + card.name)
connection.commit()
print('Saved.')
The saved amount was 1231 records, and then only the first print runs, (downloading card...) and the other 2 at the end of the code are ignored.
We’re going to need to see more code there - you did the sequestration of if’s and the call to the bank - but what does the loop do? where does the variable "card" come from? How is the table created? And above all - what happens when the writing fails? does it first print and moves on to the next card? Or the program stops and does nothing else?
– jsbueno
In particular this should not even happen - my guess is that you are calling this code inside a block "Try...except" more external - some error happens there, and except lets it pass blank.
– jsbueno