You keep setting `res` and only using the last value from `res=raw_send_recv(".\r\n\")`.  You should be checking the value from each call if you think each will fail.