It’s not a good idea to flip off a cop after getting a speeding ticket — even though a federal appeals court says it’s perfectly legal.

The judges in the Sixth Circuit in Michigan ruled unanimously that a Detroit-area cop was in the wrong when he gave a woman a more serious level of ticket after she gave him the finger during a traffic stop.

The incident began when Debra Cruise-Gulyas was pulled over in the suburban Detroit town of Taylor back in 2017.

The officer gave her a ticket. But rather then just letting it go, Cruise-Gulyas gave Officer Matthew Minard the bird.

Apparently angered by this, Minard then pulled her over a second time and changed the ticket to a more serious speeding offense.

Cruise-Gulyas took the case to court, arguing that her free speech rights and rights against unreasonable seizure were violated.

On Wednesday, the court ruled 3-0 in her favor — arguing that Minard “should have known better,” despite the driver’s ill-mannered gesture. The ruling allows a suit by the woman to proceed.

With Post wires