From d866fcc48f076c3f9c639b68d114015507059e16 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 15 May 2010 10:29:21 -0600 Subject: [PATCH] Fix #5501 (Error after query of social metadata if ISBN not find) --- src/calibre/ebooks/metadata/amazon.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/metadata/amazon.py b/src/calibre/ebooks/metadata/amazon.py index d1473be8f0..1713d044f5 100644 --- a/src/calibre/ebooks/metadata/amazon.py +++ b/src/calibre/ebooks/metadata/amazon.py @@ -19,12 +19,18 @@ AWS_NS = 'http://webservices.amazon.com/AWSECommerceService/2005-10-05' def AWS(tag): return '{%s}%s'%(AWS_NS, tag) -def check_for_errors(root): +class ISBNNotFound(ValueError): + pass + +def check_for_errors(root, isbn): err = root.find('.//'+AWS('Error')) if err is not None: + text = etree.tostring(err, method='text', pretty_print=True, + encoding=unicode) + if 'AWS.InvalidParameterValue'+isbn in text: + raise ISBNNotFound(isbn) raise Exception('Failed to get metadata with error: '\ - + etree.tostring(err, method='text', pretty_print=True, - encoding=unicode)) + + text) def get_social_metadata(title, authors, publisher, isbn): mi = MetaInformation(title, authors) @@ -32,7 +38,10 @@ def get_social_metadata(title, authors, publisher, isbn): br = browser() response_xml = br.open('http://status.calibre-ebook.com/aws/metadata/'+isbn).read() root = etree.fromstring(response_xml) - check_for_errors(root) + try: + check_for_errors(root, isbn) + except ISBNNotFound: + return mi mi.title = root.findtext('.//'+AWS('Title')) authors = [x.text for x in root.findall('.//'+AWS('Author'))] if authors: