Port to Python 3.

* Use `except Foo as bar` instead of `except Foo, bar` (this is also
  compatible with Python 2).
* Decode command output as UTF-8.
* Update shebang.