Redox activity is an important indicator for evaluating electrochemical biosensors. In this work, we have successfully polymerized indole-5-carboxylic acid into poly-5-carboxyindole nanomaterials (PI-5-CA), using its superior redox activity, and introduced carboxylated single-walled carbon nanotubes (C-SWCNTs) to synthesize a composite material. Finally, a synthesized composite material was used for the modification of the glass carbon electrode to fabricate the PI-5-CA/C-SWCNTs/GCE-based immunosensor and was successfully applied for the sensitive detection of E. coli O157:H7. The fabricated immunosensor exhibited an outstanding electrocatalytic activity toward the detection of E. coli O157:H7 with a remarkably lowest limit of detection (2.5 CFU/ml, LOD = 3 SD/k, n = 3) and has a wide linear range from 2.98×101 to 2.98×107 CFU/ml. Inspired from the excellent results, the fabricated electrode was applied for the detection of bacteria from real samples (water samples) with a good recovery rate (98.13–107.69%) as well as an excellent stability and specificity. Owing to its simple preparation, excellent performance, and detection time within 30 min, our proposed immunosensor will open a new horizon in different fields for the sensitive detection of bacteria from real samples.