Correct exception handling

Previously, it was possible for an exception to be hidden and cause other
errors for example:
    UnboundLocalError: local variable 'port' referenced before assignment
was previously occuring if e.status_code != 404

Fixes bug: 1245700

Change-Id: I27e44ffd33a73c88745de8fda8fd7c374435808a
Merge "Correct exception handling"