A copy of any mandate that justifies the detention of the petitioner must be attached to the affidavit and the original mandate produced at the hearing. Petition for a Writ of Habeas Corpus under 28 USC 2241.Category Representing Yourself (Pro Se). First, a U.S.C. § 2254 allows us to file a petition for Habeas Corpus when the client is in custody under sentence of a state court and is in a state prison. Any defendant who has been convicted of a New York state crime in a proceeding should be aware of their right to file a petition for a Writ of Habeas Corpus. This article addresses a defendant's right to file a federal petition for a writ of habeas corpus from a conviction in a state court. If you are incarcerated in a federal prison, you cannot file for state habeas corpus. You must file a petition for federal habeas corpus. A Writ of Habeas Corpus is a civil proceeding that is available in both State and Federal Court to challenge the legality of imprisonment. § 2241 provides the same statutory right to habeas corpus relief for challenges in federal court to state court proceedings.