Skip to content

Commit 31bee48

Browse files
Handle error case
For list action, the channel might not have localizations.
1 parent 9e0a102 commit 31bee48

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

python/channel_localizations.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,12 @@ def list_channel_localizations(youtube, channel_id):
118118
id=channel_id
119119
).execute()
120120

121-
localizations = results['items'][0]['localizations']
122-
123-
for language, localization in localizations.iteritems():
124-
print 'Channel description is \'%s\' in language \'%s\'' % (localization['description'], language)
125-
121+
if 'localizations' in results['items'][0]:
122+
localizations = results['items'][0]['localizations']
123+
for language, localization in localizations.iteritems():
124+
print 'Channel description is \'%s\' in language \'%s\'' % (localization['description'], language)
125+
else:
126+
print 'There aren\'t any localizations for this channel yet.'
126127

127128
if __name__ == '__main__':
128129
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)