Two Bronx men were locked up and left to rot in a filthy jail cell for nearly a week after a pair of cops mistook their candy for a bag of crack.

The “drugs” were finally tested five days later and determined to be popular Coco (coconut) Candy. The charges were dropped.

The trouble began the night of Jan. 15, as José Pena, a 48-year-old plumber, and his longtime pal and colleague Cesar Rodriguez, 33, were headed to a party, and decided to stop at a bodega on 181st Street and the Grand Concourse.

When they came out, cops were waiting and asked to search their Ford minivan. “I said ‘Go search.’ I even opened the door,” Rodriguez told The Post.

An officer rummaged around, came out holding a “Hello Kitty” sandwich bag, and shouted “Bingo!” the men said.

“It’s only candy!” Rodriguez said, as the cops handcuffed him and Pena, and several other police cars rushed to the scene.

Rodriguez said he buys a 50-cent bag of Coco Candy, a hard coconut-based treat, almost every day. Because it easily crumbles, he puts it in a sandwich bag.

“Can you test it? Can you taste it?” Rodriguez asked the cops. “Shut up!” they replied.

“I didn’t know having candy was a crime,” he said.

The men’s lawyer, Neal Wallerstein, said the cops could have realized their mistake quickly.

“That’s the reason why they have a field-test kit,” he said, referring to the NYPD’s portable drug identification equipment.

But Wallerstein said cops just needed their noses.

“It smells like sugar,” he said.

Instead, the two men were jailed for crack possession. Pena got out after three days, but Rodriguez was held two more, until Thursday morning.

The Bronx District Attorney’s office confirmed that the case was dropped after authorities realized there were no drugs. The NYPD had no comment.

Rodriguez said he still loves Coco Candy.

“It’s really sweet,” he said. “I could get addicted to this candy.”