import serial modem = serial.Serial(port='COM8', baudrate=9600) modem.write(("AT"+"\r\n").encode())