Try rebuild http object to solve connect error instead of restart the script.
Minor edit.