Anthony Weiner was done dirty by the judge who gave him 21 months in prison ... at least that's how he and his lawyers see it.

In fact, Weiner's team thinks he shouldn't have gotten ANY time behind bars, especially because the judge acknowledged Weiner's treatment program has shown promise. His attorney Arlo Devlin-Brown says the judge chose to make an example out of Weiner purely because of his celebrity.

Prosecutors had recommended up to 27 months, and the judge could have given Weiner up to 10 years -- so you'd think he'd be grateful for the 21-month sentence. Apparently not.

As Devlin-Brown puts it ... the judge used Weiner to send a message to other famous people to not follow his footsteps, but this "has resulted in a punishment more severe than it had to be given the unusual facts and circumstances of this case."

Devlin-Brown seems to be referring to the fact Weiner claims the 15-year-old girl contacted him first. The judge dismissed that argument, saying, "She is a minor. She is a victim."