Handle a client connection request.

def _handle_connect(self, sid, namespace):
        """Handle a client connection request."""
        namespace = namespace or '/'
        self.manager.connect(sid, namespace)
        if self.always_connect:
            self._send_packet(sid, packet.Packet(packet.CONNECT,
                                                 namespace=namespace))
        fail_reason = None
        try:
            success = self._trigger_event('connect', namespace, sid,
                                          self.environ[sid])
        except exceptions.ConnectionRefusedError as exc:
            fail_reason = exc.error_args
            success = False

        if success is False:
            if self.always_connect:
                self.manager.pre_disconnect(sid, namespace)
                self._send_packet(sid, packet.Packet(
                    packet.DISCONNECT, data=fail_reason, namespace=namespace))
            self.manager.disconnect(sid, namespace)
            if not self.always_connect:
                self._send_packet(sid, packet.Packet(
                    packet.ERROR, data=fail_reason, namespace=namespace))
            if sid in self.environ:  # pragma: no cover
                del self.environ[sid]
            return False
        elif not self.always_connect:
            self._send_packet(sid, packet.Packet(packet.CONNECT,
                                                 namespace=namespace))