'pyarrow._flight.FlightUnauthenticatedError'> : Flight returned unauthenticated error

I’m running Dremio community edition on docker , trying to connect using sample code snippet below but always got unauthenticated error

> <class 'pyarrow._flight.FlightUnauthenticatedError'> : Flight returned unauthenticated error, with message:

My code snippet

class BasicAuthClientAuthHandler(flight.ClientAuthHandler):
def init(self, username, password):
super().init()
self.username = username
self.password = password

def authenticate(self, outgoing, incoming):
    logger.debug("Sending basic auth credentials")
    outgoing.write(self.username.encode('utf-8'))
    outgoing.write(self.password.encode('utf-8'))
    #outgoing.close()
    logger.debug("Waiting for auth response")
    incoming.read()  # blocks until server accepts or rejects

def get_token(self):
    return b""  # Optional: implement if server returns a token

class DremioClient:
def init(self, host, port, username, password):
self.location = f"grpc+tcp://{host}:{port}"
logger.info(f"Connecting to Dremio at {self.location}")
self.client = flight.FlightClient(self.location)
self._auth(username, password)

def _auth(self, username, password):
    logger.info(f"Authenticating as {username}")
    auth_handler = BasicAuthClientAuthHandler(username, password)
    self.client.authenticate(auth_handler)
    logger.info("Authentication successful")

Any advise how to fix this code

Hey @snasef !

I don’t know where you took this code snippet.

If you want to start using pyarrow client with Dremio, you could check out our public github repo with Python Arrow client example over here - Link to client examples

There is a readme with all the details on how to connect to different versions of Dremio. Plus, you could double-check your code with an existing example from this repo.