I think it is part temperament, i.e flexibility, open-mindedness, sense of humour combined with either or both of:
a) good level of resources: social, economic otherwise
b) less restrictive expectations of how things should be
The key, for me, has been to appreciate the good things and general curiousness. The ability to amuse oneself and be resourceful and not shy about needing help, when and if you do, also helps! I also think doing things to develop your interests and be part of your new community also can give new horizons in new places.
I have had both difficult patches of being abroad (living in mainland Europe in a place where I had bad work / life balance in bad quality accommodation was never going to be happy, no matter where in the world I was living!) and loving and adopting where we are now (good work / life balance, love where we live, have good balance of urban and nature, cost of living is not insane, nice balance of diverse and lovely friends).
So, to me, it is a combination on personal / internal resources and structural / external circumstances that either come together in some kinda divine, expat kinda way and when the structural or external stuff gets you down, getting on with it and knowing that it will pass and it is not forever. So maybe it's about being realistic?