Python google.appengine.api.urlfetch.DownloadError() Examples
The following are 9
code examples of google.appengine.api.urlfetch.DownloadError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
google.appengine.api.urlfetch
, or try the search function
.
Example #1
Source File: http_client.py From pledgeservice with Apache License 2.0 | 6 votes |
def _handle_request_error(self, e, url): if isinstance(e, urlfetch.InvalidURLError): msg = ("The Stripe library attempted to fetch an " "invalid URL (%r). This is likely due to a bug " "in the Stripe Python bindings. Please let us know " "at support@stripe.com." % (url,)) elif isinstance(e, urlfetch.DownloadError): msg = "There was a problem retrieving data from Stripe." elif isinstance(e, urlfetch.ResponseTooLargeError): msg = ("There was a problem receiving all of your data from " "Stripe. This is likely due to a bug in Stripe. " "Please let us know at support@stripe.com.") else: msg = ("Unexpected error communicating with Stripe. If this " "problem persists, let us know at support@stripe.com.") msg = textwrap.fill(msg) + "\n\n(Network error: " + str(e) + ")" raise error.APIConnectionError(msg)
Example #2
Source File: storage_api.py From billing-export-python with Apache License 2.0 | 6 votes |
def do_request_async(self, url, method='GET', headers=None, payload=None, deadline=None, callback=None): """Inherit docs. This method translates urlfetch exceptions to more service specific ones. """ if headers is None: headers = {} if 'x-goog-api-version' not in headers: headers['x-goog-api-version'] = '2' headers['accept-encoding'] = 'gzip, *' try: resp_tuple = yield super(_StorageApi, self).do_request_async( url, method=method, headers=headers, payload=payload, deadline=deadline, callback=callback) except urlfetch.DownloadError, e: raise errors.TimeoutError( 'Request to Google Cloud Storage timed out.', e)
Example #3
Source File: http_client.py From shippo-python-client with MIT License | 6 votes |
def _handle_request_error(self, e, url): if isinstance(e, urlfetch.InvalidURLError): msg = ("The Shippo library attempted to fetch an " "invalid URL (%r). This is likely due to a bug " "in the Shippo Python bindings. Please let us know " "at support@goshippo.com." % (url,)) elif isinstance(e, urlfetch.DownloadError): msg = "There was a problem retrieving data from Shippo." elif isinstance(e, urlfetch.ResponseTooLargeError): msg = ("There was a problem receiving all of your data from " "Shippo. This is likely due to a bug in Shippo. " "Please let us know at support@goshippo.com.") else: msg = ("Unexpected error communicating with Shippo. If this " "problem persists, let us know at support@goshippo.com.") msg = textwrap.fill(msg) + "\n\n(Network error: " + str(e) + ")" raise error.APIConnectionError(msg)
Example #4
Source File: storage_api.py From MyLife with MIT License | 6 votes |
def do_request_async(self, url, method='GET', headers=None, payload=None, deadline=None, callback=None): """Inherit docs. This method translates urlfetch exceptions to more service specific ones. """ if headers is None: headers = {} if 'x-goog-api-version' not in headers: headers['x-goog-api-version'] = '2' headers['accept-encoding'] = 'gzip, *' try: resp_tuple = yield super(_StorageApi, self).do_request_async( url, method=method, headers=headers, payload=payload, deadline=deadline, callback=callback) except urlfetch.DownloadError, e: raise errors.TimeoutError( 'Request to Google Cloud Storage timed out.', e)
Example #5
Source File: rpc.py From python-docs-samples with Apache License 2.0 | 6 votes |
def get(self): # [START urlfetch-rpc] rpc = urlfetch.create_rpc() urlfetch.make_fetch_call(rpc, 'http://www.google.com/') # ... do other things ... try: result = rpc.get_result() if result.status_code == 200: text = result.content self.response.write(text) else: self.response.status_int = result.status_code self.response.write('URL returned status code {}'.format( result.status_code)) except urlfetch.DownloadError: self.response.status_int = 500 self.response.write('Error fetching URL') # [END urlfetch-rpc]
Example #6
Source File: storage_api.py From luci-py with Apache License 2.0 | 6 votes |
def do_request_async(self, url, method='GET', headers=None, payload=None, deadline=None, callback=None): """Inherit docs. This method translates urlfetch exceptions to more service specific ones. """ if headers is None: headers = {} if 'x-goog-api-version' not in headers: headers['x-goog-api-version'] = '2' headers['accept-encoding'] = 'gzip, *' try: resp_tuple = yield super(_StorageApi, self).do_request_async( url, method=method, headers=headers, payload=payload, deadline=deadline, callback=callback) except urlfetch.DownloadError, e: raise errors.TimeoutError( 'Request to Google Cloud Storage timed out.', e)
Example #7
Source File: storage_api.py From luci-py with Apache License 2.0 | 6 votes |
def do_request_async(self, url, method='GET', headers=None, payload=None, deadline=None, callback=None): """Inherit docs. This method translates urlfetch exceptions to more service specific ones. """ if headers is None: headers = {} if 'x-goog-api-version' not in headers: headers['x-goog-api-version'] = '2' headers['accept-encoding'] = 'gzip, *' try: resp_tuple = yield super(_StorageApi, self).do_request_async( url, method=method, headers=headers, payload=payload, deadline=deadline, callback=callback) except urlfetch.DownloadError, e: raise errors.TimeoutError( 'Request to Google Cloud Storage timed out.', e)
Example #8
Source File: main.py From hackernewsbot with MIT License | 5 votes |
def task(stories): def check_story(rpc): try: result = rpc.get_result() story = json.loads(result.content) if story and story.get('score') >= 100: StoryPost.add(story) elif story and story.get('score'): # api returned a comment once (issue with id 21447853) logging.info('STOP: {id} has low score ({score})'.format(**story)) elif story: logging.info('STOP: {id} has no score'.format(**story)) else: logging.info("STOP: story was probably deleted/flagged") except urlfetch.DownloadError as ex: logging.exception(ex) except ValueError as ex: logging.info(result.content) logging.exception(ex) # stringify ids for use in memcache and convert to set for later ids = set(str(story_id) for story_id in stories) logging.info('checking stories: {}'.format(ids)) # get stories that we already posted to reduce the number of requests cached_stories = set(memcache.get_multi(ids).keys()) logging.info('cached stories: {}'.format(cached_stories)) # remove stories we know about from stories that we need to check stories_to_check = ids.difference(cached_stories) rpcs = map(lambda id: item_async(id, check_story), stories_to_check) for rpc in rpcs: rpc.wait()
Example #9
Source File: rpc_test.py From python-docs-samples with Apache License 2.0 | 5 votes |
def test_url_fetch_rpc_error(urlfetch_mock, app): urlfetch_mock.DownloadError = urlfetch.DownloadError get_result_mock = mock.Mock( side_effect=urlfetch.DownloadError()) urlfetch_mock.create_rpc = mock.Mock( return_value=mock.Mock(get_result=get_result_mock)) response = app.get('/', status=500) assert 'Error fetching URL' in response.body