<s> import asyncio <EOL> import json <EOL> from autobahn . asyncio . websocket import WebSocketClientProtocol , WebSocketClientFactory <EOL> class AuthAPIClientProtocol ( WebSocketClientProtocol ) : <EOL> def onOpen ( self ) : <EOL> request = { <EOL> '<STR_LIT>' : '<STR_LIT:POST>' , '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT:args>' : { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , '<STR_LIT>' : False , '<STR_LIT>' : False <EOL> } <EOL> } <EOL> self . sendMessage ( json . dumps ( request ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> self . sendMessage ( json . dumps ( request ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> request = { <EOL> '<STR_LIT>' : '<STR_LIT:POST>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT:args>' : { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> self . sendMessage ( json . dumps ( request ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> def onMessage ( self , payload , isBinary ) : <EOL> message = json . loads ( payload . decode ( '<STR_LIT:utf8>' ) ) <EOL> print ( "<STR_LIT>" . format ( message ) ) <EOL> if '<STR_LIT>' in message and message [ '<STR_LIT>' ] [ '<STR_LIT:url>' ] == "<STR_LIT>" : <EOL> request = { <EOL> '<STR_LIT>' : '<STR_LIT:POST>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : message [ '<STR_LIT:data>' ] [ '<STR_LIT>' ] <EOL> } <EOL> self . sendMessage ( json . dumps ( request ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> factory = WebSocketClientFactory ( "<STR_LIT>" , debug = False ) <EOL> factory . protocol = AuthAPIClientProtocol <EOL> loop = asyncio . get_event_loop ( ) <EOL> coro = loop . create_connection ( factory , '<STR_LIT:127.0.0.1>' , <NUM_LIT> ) <EOL> loop . run_until_complete ( coro ) <EOL> loop . run_forever ( ) <EOL> loop . close ( ) </s>
