while 1: try: data = fd.read(1024) except socket.error, e: print "Error reading data:", e sys.exit(3)
if not len(data): break bytesread += len(data) sys.stdout.write(data)
if fd.info().has_key('Content-Length') and long(fd.info()['Content-Length']) != long(bytesread): print "Expected a document of size %d, but read %d bytes" % (long(fd.info()['Content-Length']), bytesread) sys.exit(4)
Related Scripts with Example Source Code in same category :