Skip to content

Commit 3732e66

Browse files
Handle error case
When listing localizations, handle case where the channel section doesn't have any yet.
1 parent 31bee48 commit 3732e66

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

python/channel_section_localizations.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,14 @@ def list_channel_section_localizations(youtube, args):
124124
id=args.channel_section_id
125125
).execute()
126126

127-
localizations = results['items'][0]['localizations']
128-
129-
for language, localization in localizations.iteritems():
130-
print('The channel section title is \'%s\' in language \'%s\'.' %
131-
(localization['title'], language))
127+
if 'localizations' in results['items'][0]:
128+
localizations = results['items'][0]['localizations']
129+
130+
for language, localization in localizations.iteritems():
131+
print('The channel section title is \'%s\' in language \'%s\'.' %
132+
(localization['title'], language))
133+
else:
134+
print 'This channel section does not have localizations yet.'
132135

133136
# Call the API's channelSections.list method to list localizations for all
134137
# channel sections in the authorizing user\'s channel. This function might

0 commit comments

Comments
 (0)