Fix error "UnboundLocalError: local variable 'hoststr' referenced before assignment"