algorithmiaio/algorithmia-python

Authentication message failures

Closed this issue · 0 comments

zeryx commented

elif args.cmd == 'languages':
response = CLI().list_languages(client)
print("{:<25} {:<35}".format('Name','Description'))
for lang in response:
print("{:<25} {:<35}".format(lang['name'],lang['display_name']))

the new languages endpoint is super useful for helping algo devs understand how to programmatically access algorithms; however the current version can sometimes swallow errors by assuming that the output is always properly formatted.

This form of exception can occur either with a 500 or 400 response:

$ algo languages
Name                      Description                        
Traceback (most recent call last):
  File "/usr/local/anaconda3/bin/algo", line 8, in <module>
    sys.exit(main())
  File "/usr/local/anaconda3/lib/python3.8/site-packages/Algorithmia/__main__.py", line 207, in main
    print("{:<25} {:<35}".format(lang['name'],lang['display_name']))
TypeError: string indices must be integers

To rectify this, we should check to ensure that the lang response is properly formatted and contains all relevant fields first, otherwise return the response unaltered.