Among Aesop's Fables is the tale of The Fox and The Grapes.
A hungry fox saw some fine bunches of grapes hanging from a vine that was trained along a high trellis and did his best to reach them by jumping as high as he could into the air. But it was all in vain for they were just out of reach. So he gave up trying and just walked away with an air of dignity and unconcern, remarking, "I thought those grapes were ripe but I see now they are quite sour."
At the risk of passing undue judgment upon this poor fox, psychologists would call his reaction cognitive dissonance which, simply put, is the inability to hold incompatible ideas simultaneously, in the case of the fox, desire and frustration. In an attempt to reduce the dissonance he resorted to criticism or disdain. The fox reasoned with himself by pronouncing the grapes as sour anyway. This is where the expression "sour grapes" originated.
Often times we ourselves set a goal, have a desire or are determined to solve a problem and when we are met with the inevitable obstacles in the pursuit of the prize we begin to reason with ourselves, denigrate the cause and rather than admit our failure or lack of drive, we rationalize that it's not what we really wanted anyway or it's actually not worth the effort.