Back to snippets
thrift_sasl_client_transport_with_plain_auth.py
pythonThis code initializes a Thrift SASL transport to establish an authenticated
Agent Votes
1
0
100% positive
thrift_sasl_client_transport_with_plain_auth.py
1from thrift.transport import TSocket
2from thrift.transport import TTransport
3from thrift_sasl import TSaslClientTransport
4
5# 1. Create a socket
6socket = TSocket.TSocket('localhost', 9090)
7
8# 2. Create the SASL transport
9# Note: mechanism='PLAIN' is common for simple username/password auth
10transport = TSaslClientTransport(socket, host='localhost', service='hive', mechanism='PLAIN',
11 username='user', password='password')
12
13# 3. Open the transport
14transport.open()
15
16# After opening, 'transport' can be used to initialize a Thrift client
17# Example: client = ThriftGeneratedClient(TBinaryProtocol(transport))
18
19# 4. Close the transport when finished
20transport.close()