The solution was basically to add a while loop to retry the paste operation with a waiting interval between each attempt, until it succeeds.