~ubuntu-branches/ubuntu/trusty/python-boto/trusty

« back to all changes in this revision

Viewing changes to boto/cloudsearch/search.py

  • Committer: Package Import Robot
  • Author(s): Eric Evans
  • Date: 2013-08-13 13:56:47 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20130813135647-o43z7y15uid87fzl
Tags: 2.10.0-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
 
39
39
class SearchResults(object):
40
 
    
41
40
    def __init__(self, **attrs):
42
41
        self.rid = attrs['info']['rid']
43
42
        # self.doc_coverage_pct = attrs['info']['doc-coverage-pct']
289
288
        params = query.to_params()
290
289
 
291
290
        r = requests.get(url, params=params)
292
 
        data = json.loads(r.content)
 
291
        try:
 
292
            data = json.loads(r.content)
 
293
        except ValueError, e:
 
294
            if r.status_code == 403:
 
295
                msg = ''
 
296
                import re
 
297
                g = re.search('<html><body><h1>403 Forbidden</h1>([^<]+)<', r.content)
 
298
                try:
 
299
                    msg = ': %s' % (g.groups()[0].strip())
 
300
                except AttributeError:
 
301
                    pass
 
302
                raise SearchServiceException('Authentication error from Amazon%s' % msg)
 
303
            raise SearchServiceException("Got non-json response from Amazon")
293
304
        data['query'] = query
294
305
        data['search_service'] = self
295
306