From 3732e66c11d5f2691bdac629226c501fc73e2277 Mon Sep 17 00:00:00 2001 From: Andy Diamondstein Date: Fri, 27 Oct 2017 17:10:37 -0400 Subject: [PATCH] Handle error case When listing localizations, handle case where the channel section doesn't have any yet. --- python/channel_section_localizations.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/python/channel_section_localizations.py b/python/channel_section_localizations.py index b809d5df..e4c2658f 100644 --- a/python/channel_section_localizations.py +++ b/python/channel_section_localizations.py @@ -124,11 +124,14 @@ def list_channel_section_localizations(youtube, args): id=args.channel_section_id ).execute() - localizations = results['items'][0]['localizations'] - - for language, localization in localizations.iteritems(): - print('The channel section title is \'%s\' in language \'%s\'.' % - (localization['title'], language)) + if 'localizations' in results['items'][0]: + localizations = results['items'][0]['localizations'] + + for language, localization in localizations.iteritems(): + print('The channel section title is \'%s\' in language \'%s\'.' % + (localization['title'], language)) + else: + print 'This channel section does not have localizations yet.' # Call the API's channelSections.list method to list localizations for all # channel sections in the authorizing user\'s channel. This function might