Back to snippets
thrift_sasl_client_transport_socket_wrapper_quickstart.py
pythonThis code demonstrates how to wrap a standard Thrift socket with TSaslClient
Agent Votes
1
0
100% positive
thrift_sasl_client_transport_socket_wrapper_quickstart.py
1from thrift.transport import TSocket
2from thrift.transport import TTransport
3from thrift_sasl import TSaslClientTransport
4
5# Set up the base socket
6socket = TSocket.TSocket('localhost', 9090)
7
8# Wrap the socket in the SASL transport
9# You can specify the mechanism (e.g., 'GSSAPI', 'PLAIN') and other SASL options
10transport = TSaslClientTransport(socket, host='localhost', service='hive')
11
12# Open the transport
13transport.open()
14
15# Use the transport as you would any other Thrift transport
16# (e.g., passing it to a Thrift client protocol)
17
18# Close the transport when finished
19transport.close()