The story
From Aesop's fable The Fox and the Grapes, in which a fox, unable to reach grapes it is seeking, convinces itself that they must have been unripe (therefore, sour) all along and so not worth trying for in the first place.
Etymology from Wiktionary, CC BY-SA 4.0.