Check for errors in apt.py, fixes #3993

Sorry for the extra commits, I misread cmd.run and thought it was returning a dictionary.

Fixes #3993