示例#1
0
 def qrLogin(self, headers):
     sys_name = "BE-Team"
     transport = THttpClient(self.lineServer + '/api/v4/TalkService.do')
     transport.setCustomHeaders(headers)
     protocol = TCompactProtocol(transport)
     talk = TalkService.Client(protocol)
     qr_code = talk.getAuthQrcode(keepLoggedIn=True,
                                  systemName=sys_name,
                                  returnCallbackUrl=True)
     transport.close()
     print(qr_code.callbackUrl)
     headers["X-Line-Access"] = qr_code.verifier
     transport = THttpClient(self.lineServer + '/api/v4p/rs')
     transport.setCustomHeaders(headers)
     protocol = TCompactProtocol(transport)
     auth = TalkService.Client(protocol)
     get_access = json.loads(
         requests.get(self.lineServer + '/Q', headers=headers).text)
     login_request = LoginRequest()
     login_request.type = 1
     login_request.identityProvider = 1
     login_request.keepLoggedIn = True
     login_request.systemName = sys_name
     login_request.verifier = get_access['result']['verifier']
     result = auth.loginZ(login_request)
     transport.close()
     return result.authToken
示例#2
0
def qrLogin():
    headers= {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36",
        "X-Line-Application": "CHROMEOS\t2.3.2\tChrome OS\t1",
        "x-lal": "en_ID",
        "X-Line-Carrier": "51010,1-0"
    }
    sys_name = "BE-Team"
    transport = THttpClient("https://ga2.line.naver.jp" + '/api/v4/TalkService.do')
    transport.setCustomHeaders(headers)
    protocol = TCompactProtocol(transport)
    talk = BoteaterService.Client(protocol)
    qr_code = talk.getAuthQrcode(keepLoggedIn=True, systemName=sys_name, returnCallbackUrl=True)
    transport.close()
    print(qr_code.callbackUrl)
    headers["X-Line-Access"] = qr_code.verifier
    transport = THttpClient("https://ga2.line.naver.jp" + '/api/v4p/rs')
    transport.setCustomHeaders(headers)
    protocol = TCompactProtocol(transport)
    auth = BoteaterService.Client(protocol)
    get_access = json.loads(requests.get("https://ga2.line.naver.jp" + '/Q', headers=headers).text)
    login_request = LoginRequestStruct()
    login_request.type = 1
    login_request.identityProvider = 1
    login_request.keepLoggedIn = True
    login_request.systemName = sys_name
    login_request.verifier = get_access['result']['verifier']
    result = auth.loginZ(login_request)
    transport.close()
    return result.authToken
示例#3
0
class LuminateOnlineClient(LuminatOnline.Client):

  def __init__(self):
    self.transport = THttpClient('localhost', 9090, '/luminate.binary')
    self.transport.open()
    LuminatOnline.Client.__init__(self, TBinaryProtocol.TBinaryProtocol(self.transport))

  def close(self):
    self.transport.close() 
示例#4
0
def getMid(my_token):
    headers= {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36",
        "X-Line-Application": "CHROMEOS\t2.3.2\tChrome OS\t1",
        "x-lal": "en_ID",
        "X-Line-Carrier": "51010,1-0"
    }
    headers["X-Line-Access"] = my_token
    transport = THttpClient("https://ga2.line.naver.jp" + '/api/v4/TalkService.do')
    transport.setCustomHeaders(headers)
    protocol = TCompactProtocol(transport)
    talk = BoteaterService.Client(protocol)
    mid = talk.getProfile().mid
    transport.close()
    return mid
示例#5
0
class Connection(object):
    """
    Class to manage basic transport and protocol.
    User should not use instances of this class directly.
    The instances should be managed by a Client object.

    """
    def __init__(self,
                 host,
                 port,
                 transport_type,
                 protocol_type,
                 retry_timeout,
                 retry_times,
                 use_ssl,
                 use_http,
                 authentication,
                 keep_alive=False):

        self.host = host
        self.port = port
        self.use_ssl = use_ssl
        self.use_http = use_http
        self.authentication = authentication
        self.keep_alive = keep_alive

        self._transport_type = THRIFT_TRANSPORTS[transport_type]
        self._protocol_type = THRIFT_PROTOCOLS[protocol_type]
        self._retry_timeout = retry_timeout
        self._retry_times = retry_times
        self._rebuild_protocol()
        self._initialized = True

    def _rebuild_protocol(self):
        """
        Rebuild the transport, protocol from the configuration.
        Should not be used directly by users.
        Returns:
            None
        """
        if self.use_http:
            # if use http transport,
            prefix = 'https://' if self.use_ssl else 'http://'
            self.transport = THttpClient(uri_or_host=prefix + self.host + ':' +
                                         str(self.port))
            self.protocol = TBinaryProtocol.TBinaryProtocol(self.transport)
            return

        if self.use_ssl:
            from thrift.transport.TSSLSocket import TSSLSocket
            socket = TSSLSocket(host=self.host,
                                port=self.port,
                                validate=False,
                                socket_keepalive=self.keep_alive)
        else:
            socket = TSocket(host=self.host,
                             port=self.port,
                             socket_keepalive=self.keep_alive)

        if self.authentication:
            socket = TSaslClientTransport(
                socket,
                host=self.host,
                service=self.authentication.service,
                mechanism=self.authentication.mechanism,
                username=self.authentication.username,
                password=self.authentication.password,
            )

        self.transport = self._transport_type(socket)
        self.protocol = self._protocol_type(self.transport)

    def is_open(self):
        return self.transport.isOpen()

    def open(self):
        if self.transport.isOpen():
            return
        logger.debug("Opening thrift transport throught TCP connection.")
        self.transport.open()

    def close(self):
        if not self.transport.isOpen():
            return
        if logger is not None:
            logger.debug("Closing thrift transport to {}:{}.".format(
                self.host, self.port))
        self.transport.close()

    def _reconnect(self):
        """
        Method to rebuild the connection with thrift server. Should not be used by the user directly.
        Returns: None

        """
        if not self.transport.isOpen():
            logger.info(
                "Connection lose is detected and start reconnecting to the target thrift server."
            )
            for i in range(self._retry_times):
                if self.transport.isOpen():
                    logger.info(
                        "Reconnection success after retrying {} times.".format(
                            i))
                    return True
                self._rebuild_protocol()
                try:
                    logger.info("Starting reconnection to thrift server.")
                    self.transport.open()
                    logger.info(
                        "Reconnection success after retrying {} times.".format(
                            i + 1))
                    return True
                except TTransportException:
                    logger.error("Reconnected {} times but failed.".format(i +
                                                                           1))
                    time.sleep(self._retry_timeout)
            if not self.transport.isOpen():
                logger.error(
                    "Failed to rebuild connection with target thrift server.")
                raise TTransportException(
                    type=TTransportException.NOT_OPEN,
                    message=
                    "Failed to rebuild connection with target thrift server.")
            return False