Indeed, I should have used the get('metadata-flavor', '') instead of checking like this.
In the new implementation (using urllib2 instead of httplib2), it is not needed anymore.