I made some modifications to your code and put comments where it differs from yours (corrects your errors): import socket import base64 import time, datetime .