import socket


def check_port_occupied(port, address="127.0.0.1"):
    """
    Check if a port is occupied by attempting to bind the socket

    :return: socket.error if the port is in use, otherwise False
    """
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.bind((address, port))
    except socket.error as e:
        return e
    finally:
        s.close()
    return False