Reading HTTP response from UART
This

        while ( str[pos] != '\n' ):
            length = "%s%s" % (length, str[pos])
            pos = pos + 1


could be just

        length = string.split(str[pos:], '\n')[0]