Baby roots and roots, but won't nurse!

She doesn't always do it. It's almost only at night. But she'll desperately root for my nipple, and I'll put her on it, and she'll open wide and everything, but as soon as she's on it, instead of sucking, she'll push me away. And repeat the process a million times, and then start just absolutely shrieking like I'm starving her. I don't know why! She'll nurse just fine almost all day. Only at night does she give me so much trouble, and it's breaking my heart because I don't know what the problem is or how to make her stop crying. No amount of burping or caressing or comfort makes it quit, and I feel horrible because I can't figure out why and it makes me doubt my decision to have a kid if already I can't just fix the damn problem!

What makes a baby attack your boobs like a shark, but push you away every time she actually gets the nipple?