code: def example(host, user, password, token):
      
      client = None
      try:
          if token:
              print('token login')
              client = MatrixClient(host, token=token, user_id=user)
          else:
              print('password login')
              client = MatrixClient(host)
              token = client.login_with_password(user, password)
              print('got token: %s' % token)
      except MatrixRequestError as e:
          print(e)
          if e.code == 403:
              print("Bad username or password")
              exit(2)
          elif e.code == 401:
              print("Bad username or token")
              exit(3)
          else:
              print("Verify server details.")
              exit(4)
      except MissingSchema as e:
          print(e)
          print("Bad formatting of URL.")
          exit(5)
      except InvalidSchema as e:
          print(e)
          print("Invalid URL schema")
          exit(6)
      print("is in rooms")
      for room_id, room in client.get_rooms().items():
          print(room_id)
docs: run the example.