From 2d39633db2a55fdbfe8712e4e9eeb1497c4c14ce Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 14 Jan 2020 17:01:25 -0700 Subject: [PATCH 1/3] vision: update samples to throw errors if one occurs --- vision/cloud-client/detect/beta_snippets.py | 6 ++ vision/cloud-client/detect/detect.py | 66 +++++++++++++++++++++ vision/cloud-client/detect/detect_test.py | 2 +- vision/cloud-client/detect/set_endpoint.py | 3 + 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/vision/cloud-client/detect/beta_snippets.py b/vision/cloud-client/detect/beta_snippets.py index 1a5ae27b3ebe..2fdd9c185de8 100644 --- a/vision/cloud-client/detect/beta_snippets.py +++ b/vision/cloud-client/detect/beta_snippets.py @@ -130,6 +130,9 @@ def detect_handwritten_ocr(path): for symbol in word.symbols: print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_handwritten_ocr_beta] @@ -174,6 +177,9 @@ def detect_handwritten_ocr_uri(uri): for symbol in word.symbols: print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_handwritten_ocr_gcs_beta] diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 878e8a10d4bb..332b56ae0422 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -68,6 +68,9 @@ def detect_faces(path): for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_face_detection] # [END vision_face_detection] @@ -99,6 +102,9 @@ def detect_faces_uri(uri): for vertex in face.bounding_poly.vertices]) print('face bounds: {}'.format(','.join(vertices))) + + if response.error.message: + raise Exception(response.error.message) # [END vision_face_detection_gcs] @@ -121,6 +127,9 @@ def detect_labels(path): for label in labels: print(label.description) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_label_detection] # [END vision_label_detection] @@ -140,6 +149,9 @@ def detect_labels_uri(uri): for label in labels: print(label.description) + + if response.error.message: + raise Exception(response.error.message) # [END vision_label_detection_gcs] @@ -166,6 +178,9 @@ def detect_landmarks(path): lat_lng = location.lat_lng print('Latitude {}'.format(lat_lng.latitude)) print('Longitude {}'.format(lat_lng.longitude)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_landmark_detection] # [END vision_landmark_detection] @@ -185,6 +200,9 @@ def detect_landmarks_uri(uri): for landmark in landmarks: print(landmark.description) + + if response.error.message: + raise Exception(response.error.message) # [END vision_landmark_detection_gcs] @@ -207,6 +225,9 @@ def detect_logos(path): for logo in logos: print(logo.description) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_logo_detection] # [END vision_logo_detection] @@ -226,6 +247,9 @@ def detect_logos_uri(uri): for logo in logos: print(logo.description) + + if response.error.message: + raise Exception(response.error.message) # [END vision_logo_detection_gcs] @@ -255,6 +279,9 @@ def detect_safe_search(path): print('spoofed: {}'.format(likelihood_name[safe.spoof])) print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_safe_search_detection] # [END vision_safe_search_detection] @@ -281,6 +308,9 @@ def detect_safe_search_uri(uri): print('spoofed: {}'.format(likelihood_name[safe.spoof])) print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) + + if response.error.message: + raise Exception(response.error.message) # [END vision_safe_search_detection_gcs] @@ -308,6 +338,9 @@ def detect_text(path): for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_text_detection] # [END vision_text_detection] @@ -332,6 +365,9 @@ def detect_text_uri(uri): for vertex in text.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) + + if response.error.message: + raise Exception(response.error.message) # [END vision_text_detection_gcs] @@ -358,6 +394,9 @@ def detect_properties(path): print('\tg: {}'.format(color.color.green)) print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_image_properties] # [END vision_image_property_detection] @@ -381,6 +420,9 @@ def detect_properties_uri(uri): print('\tg: {}'.format(color.color.green)) print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_image_property_detection_gcs] @@ -439,6 +481,9 @@ def detect_web(path): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_web_detection] # [END vision_web_detection] @@ -493,6 +538,9 @@ def detect_web_uri(uri): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_web_detection_gcs] @@ -519,6 +567,9 @@ def web_entities_include_geo_results(path): for entity in response.web_detection.web_entities: print('\n\tScore : {}'.format(entity.score)) print(u'\tDescription: {}'.format(entity.description)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_web_detection_include_geo] @@ -543,6 +594,9 @@ def web_entities_include_geo_results_uri(uri): for entity in response.web_detection.web_entities: print('\n\tScore : {}'.format(entity.score)) print(u'\tDescription: {}'.format(entity.description)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_web_detection_include_geo_gcs] @@ -572,6 +626,9 @@ def detect_crop_hints(path): for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_crop_hints] # [END vision_crop_hint_detection] @@ -598,6 +655,9 @@ def detect_crop_hints_uri(uri): for vertex in hint.bounding_poly.vertices]) print('bounds: {}'.format(','.join(vertices))) + + if response.error.message: + raise Exception(response.error.message) # [END vision_crop_hint_detection_gcs] @@ -634,6 +694,9 @@ def detect_document(path): for symbol in word.symbols: print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_python_migration_document_text_detection] # [END vision_fulltext_detection] @@ -667,6 +730,9 @@ def detect_document_uri(uri): for symbol in word.symbols: print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) + + if response.error.message: + raise Exception(response.error.message) # [END vision_fulltext_detection_gcs] diff --git a/vision/cloud-client/detect/detect_test.py b/vision/cloud-client/detect/detect_test.py index b7649d596d4e..f80b63ce7d64 100644 --- a/vision/cloud-client/detect/detect_test.py +++ b/vision/cloud-client/detect/detect_test.py @@ -37,7 +37,7 @@ def test_labels(capsys): def test_labels_uri(capsys): - file_name = 'gs://{}/vision/wakeupcat.jpg'.format(ASSET_BUCKET) + file_name = 'gs://{}/vision/label/wakeupcat.jpg'.format(ASSET_BUCKET) detect.detect_labels_uri(file_name) out, _ = capsys.readouterr() assert 'Labels' in out diff --git a/vision/cloud-client/detect/set_endpoint.py b/vision/cloud-client/detect/set_endpoint.py index d721ffc6bed1..4e3776c12b2f 100644 --- a/vision/cloud-client/detect/set_endpoint.py +++ b/vision/cloud-client/detect/set_endpoint.py @@ -37,6 +37,9 @@ def set_endpoint(): print('bounds: {}\n'.format(','.join(vertices))) + if response.error.message: + raise Exception(response.error.message) + if __name__ == '__main__': set_endpoint() From 68c81c4718b54765d6fc91d1f4592974d4502cad Mon Sep 17 00:00:00 2001 From: nnegrey Date: Fri, 17 Jan 2020 15:52:04 -0700 Subject: [PATCH 2/3] Add link to error page docs --- vision/cloud-client/detect/beta_snippets.py | 4 ++ vision/cloud-client/detect/detect.py | 44 +++++++++++++++++++++ vision/cloud-client/detect/set_endpoint.py | 2 + 3 files changed, 50 insertions(+) diff --git a/vision/cloud-client/detect/beta_snippets.py b/vision/cloud-client/detect/beta_snippets.py index 2fdd9c185de8..a805e423ec9a 100644 --- a/vision/cloud-client/detect/beta_snippets.py +++ b/vision/cloud-client/detect/beta_snippets.py @@ -131,6 +131,8 @@ def detect_handwritten_ocr(path): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_handwritten_ocr_beta] @@ -178,6 +180,8 @@ def detect_handwritten_ocr_uri(uri): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_handwritten_ocr_gcs_beta] diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 332b56ae0422..1ed1af490e31 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -69,6 +69,8 @@ def detect_faces(path): print('face bounds: {}'.format(','.join(vertices))) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_face_detection] @@ -103,6 +105,8 @@ def detect_faces_uri(uri): print('face bounds: {}'.format(','.join(vertices))) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_face_detection_gcs] @@ -128,6 +132,8 @@ def detect_labels(path): for label in labels: print(label.description) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_label_detection] @@ -150,6 +156,8 @@ def detect_labels_uri(uri): for label in labels: print(label.description) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_label_detection_gcs] @@ -179,6 +187,8 @@ def detect_landmarks(path): print('Latitude {}'.format(lat_lng.latitude)) print('Longitude {}'.format(lat_lng.longitude)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_landmark_detection] @@ -201,6 +211,8 @@ def detect_landmarks_uri(uri): for landmark in landmarks: print(landmark.description) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_landmark_detection_gcs] @@ -226,6 +238,8 @@ def detect_logos(path): for logo in logos: print(logo.description) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_logo_detection] @@ -248,6 +262,8 @@ def detect_logos_uri(uri): for logo in logos: print(logo.description) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_logo_detection_gcs] @@ -280,6 +296,8 @@ def detect_safe_search(path): print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_safe_search_detection] @@ -309,6 +327,8 @@ def detect_safe_search_uri(uri): print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_safe_search_detection_gcs] @@ -339,6 +359,8 @@ def detect_text(path): print('bounds: {}'.format(','.join(vertices))) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_text_detection] @@ -366,6 +388,8 @@ def detect_text_uri(uri): print('bounds: {}'.format(','.join(vertices))) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_text_detection_gcs] @@ -395,6 +419,8 @@ def detect_properties(path): print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_image_properties] @@ -421,6 +447,8 @@ def detect_properties_uri(uri): print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_image_property_detection_gcs] @@ -482,6 +510,8 @@ def detect_web(path): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_web_detection] @@ -539,6 +569,8 @@ def detect_web_uri(uri): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_web_detection_gcs] @@ -568,6 +600,8 @@ def web_entities_include_geo_results(path): print('\n\tScore : {}'.format(entity.score)) print(u'\tDescription: {}'.format(entity.description)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_web_detection_include_geo] @@ -595,6 +629,8 @@ def web_entities_include_geo_results_uri(uri): print('\n\tScore : {}'.format(entity.score)) print(u'\tDescription: {}'.format(entity.description)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_web_detection_include_geo_gcs] @@ -627,6 +663,8 @@ def detect_crop_hints(path): print('bounds: {}'.format(','.join(vertices))) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_crop_hints] @@ -656,6 +694,8 @@ def detect_crop_hints_uri(uri): print('bounds: {}'.format(','.join(vertices))) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_crop_hint_detection_gcs] @@ -695,6 +735,8 @@ def detect_document(path): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_python_migration_document_text_detection] @@ -731,6 +773,8 @@ def detect_document_uri(uri): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) # [END vision_fulltext_detection_gcs] diff --git a/vision/cloud-client/detect/set_endpoint.py b/vision/cloud-client/detect/set_endpoint.py index 4e3776c12b2f..9885b1507d64 100644 --- a/vision/cloud-client/detect/set_endpoint.py +++ b/vision/cloud-client/detect/set_endpoint.py @@ -37,6 +37,8 @@ def set_endpoint(): print('bounds: {}\n'.format(','.join(vertices))) + # For more info on error messages + # check: https://cloud.google.com/apis/design/errors if response.error.message: raise Exception(response.error.message) From e6814e620890761a486698fd3691624e4da4a75b Mon Sep 17 00:00:00 2001 From: nnegrey Date: Tue, 21 Jan 2020 11:14:58 -0700 Subject: [PATCH 3/3] Add link to error message --- vision/cloud-client/detect/beta_snippets.py | 14 +- vision/cloud-client/detect/detect.py | 154 +++++++++++--------- vision/cloud-client/detect/set_endpoint.py | 7 +- 3 files changed, 100 insertions(+), 75 deletions(-) diff --git a/vision/cloud-client/detect/beta_snippets.py b/vision/cloud-client/detect/beta_snippets.py index a805e423ec9a..d5beb4021634 100644 --- a/vision/cloud-client/detect/beta_snippets.py +++ b/vision/cloud-client/detect/beta_snippets.py @@ -131,10 +131,11 @@ def detect_handwritten_ocr(path): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_handwritten_ocr_beta] @@ -180,10 +181,11 @@ def detect_handwritten_ocr_uri(uri): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_handwritten_ocr_gcs_beta] diff --git a/vision/cloud-client/detect/detect.py b/vision/cloud-client/detect/detect.py index 1ed1af490e31..a7d3eca8759b 100644 --- a/vision/cloud-client/detect/detect.py +++ b/vision/cloud-client/detect/detect.py @@ -69,10 +69,11 @@ def detect_faces(path): print('face bounds: {}'.format(','.join(vertices))) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_face_detection] # [END vision_face_detection] @@ -105,10 +106,11 @@ def detect_faces_uri(uri): print('face bounds: {}'.format(','.join(vertices))) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_face_detection_gcs] @@ -132,10 +134,11 @@ def detect_labels(path): for label in labels: print(label.description) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_label_detection] # [END vision_label_detection] @@ -156,10 +159,11 @@ def detect_labels_uri(uri): for label in labels: print(label.description) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_label_detection_gcs] @@ -187,10 +191,11 @@ def detect_landmarks(path): print('Latitude {}'.format(lat_lng.latitude)) print('Longitude {}'.format(lat_lng.longitude)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_landmark_detection] # [END vision_landmark_detection] @@ -211,10 +216,11 @@ def detect_landmarks_uri(uri): for landmark in landmarks: print(landmark.description) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_landmark_detection_gcs] @@ -238,10 +244,11 @@ def detect_logos(path): for logo in logos: print(logo.description) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_logo_detection] # [END vision_logo_detection] @@ -262,10 +269,11 @@ def detect_logos_uri(uri): for logo in logos: print(logo.description) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_logo_detection_gcs] @@ -296,10 +304,11 @@ def detect_safe_search(path): print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_safe_search_detection] # [END vision_safe_search_detection] @@ -327,10 +336,11 @@ def detect_safe_search_uri(uri): print('violence: {}'.format(likelihood_name[safe.violence])) print('racy: {}'.format(likelihood_name[safe.racy])) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_safe_search_detection_gcs] @@ -359,10 +369,11 @@ def detect_text(path): print('bounds: {}'.format(','.join(vertices))) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_text_detection] # [END vision_text_detection] @@ -388,10 +399,11 @@ def detect_text_uri(uri): print('bounds: {}'.format(','.join(vertices))) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_text_detection_gcs] @@ -419,10 +431,11 @@ def detect_properties(path): print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_image_properties] # [END vision_image_property_detection] @@ -447,10 +460,11 @@ def detect_properties_uri(uri): print('\tb: {}'.format(color.color.blue)) print('\ta: {}'.format(color.color.alpha)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_image_property_detection_gcs] @@ -510,10 +524,11 @@ def detect_web(path): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_web_detection] # [END vision_web_detection] @@ -569,10 +584,11 @@ def detect_web_uri(uri): for image in annotations.visually_similar_images: print('\tImage url : {}'.format(image.url)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_web_detection_gcs] @@ -600,10 +616,11 @@ def web_entities_include_geo_results(path): print('\n\tScore : {}'.format(entity.score)) print(u'\tDescription: {}'.format(entity.description)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_web_detection_include_geo] @@ -629,10 +646,11 @@ def web_entities_include_geo_results_uri(uri): print('\n\tScore : {}'.format(entity.score)) print(u'\tDescription: {}'.format(entity.description)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_web_detection_include_geo_gcs] @@ -663,10 +681,11 @@ def detect_crop_hints(path): print('bounds: {}'.format(','.join(vertices))) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_crop_hints] # [END vision_crop_hint_detection] @@ -694,10 +713,11 @@ def detect_crop_hints_uri(uri): print('bounds: {}'.format(','.join(vertices))) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_crop_hint_detection_gcs] @@ -735,10 +755,11 @@ def detect_document(path): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_python_migration_document_text_detection] # [END vision_fulltext_detection] @@ -773,10 +794,11 @@ def detect_document_uri(uri): print('\tSymbol: {} (confidence: {})'.format( symbol.text, symbol.confidence)) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) # [END vision_fulltext_detection_gcs] diff --git a/vision/cloud-client/detect/set_endpoint.py b/vision/cloud-client/detect/set_endpoint.py index 9885b1507d64..44361436fed4 100644 --- a/vision/cloud-client/detect/set_endpoint.py +++ b/vision/cloud-client/detect/set_endpoint.py @@ -37,10 +37,11 @@ def set_endpoint(): print('bounds: {}\n'.format(','.join(vertices))) - # For more info on error messages - # check: https://cloud.google.com/apis/design/errors if response.error.message: - raise Exception(response.error.message) + raise Exception( + '{}\nFor more info on error messages, check: ' + 'https://cloud.google.com/apis/design/errors'.format( + response.error.message)) if __name__ == '__main__':