Gooogle Drive Api and Slot issue

Hello Everyone,

I ran into a strange problem while doing this activity already posted here : Rasa Google Drive API.

I solved this problem with following code :

class ActionQuestion(Action): # def name(self) -> Text: return “action_question”

def run(self, dispatcher: CollectingDispatcher,

        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
    import pickle
    import os.path
    from googleapiclient.discovery import build
    from google_auth_oauthlib.flow import InstalledAppFlow
    from google.auth.transport.requests import Request
    import logging

    logging.getLogger('googleapicliet.discovery_cache').setLevel(logging.ERROR)
    # If modifying these scopes, delete the file token.pickle.
    SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']

    creds = None
        # The file token.pickle stores the user's access and refresh tokens, and is
        # created automatically when the authorization flow completes for the first
        # time.
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
        # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
            # Save the credentials for the next run
        with open('token.pickle', 'wb') as token:
            pickle.dump(creds, token)

    service = build('drive', 'v3', credentials=creds)
        # Call the Drive v3 API

    page_token = None
    while True:
        response = service.files().list(q="name='Getting Started'",
                                        spaces='drive',
                                        fields='nextPageToken, files(id, name)',
                                        pageToken=page_token).execute()
        for file in response.get('files', []):
            # Process change
            dispatcher.utter_message('Found file: %s please visit the link https://drive.google.com/open?id=%s' % (file.get('name'), file.get('id')))
            dispatcher.utter_message(type(question))
        page_token = response.get('nextPageToken', None)
        if page_token is None:
            break
    return []

My issue is when instead of directly passing the name of file in these line:

        response = service.files().list(q="name='Getting Started'",
                                        spaces='drive',
                                        fields='nextPageToken, files(id, name)',
                                        pageToken=page_token).execute()

i use the tracker.get_slot method to pass the name of file like this:

    question = tracker.get_slot("document")
    response = service.files().list(q="name=question",
                                        spaces='drive',
                                        fields='nextPageToken, files(id, name)',
                                        pageToken=page_token).execute()

i get the following http error:

googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files?q=name+%3D+question&spaces=drive&fields=nextPageToken%2C+files(id%2C+name)&alt=json returned “Invalid Value”>

When running the direct values i get the following http resquest and return correct value:

googleapiclient.discovery - URL being requested: GET https://www.googleapis.com/drive/v3/files?q=name+%3D+'getting+started'&spaces=drive&fields=nextPageToken%2C+files(id%2C+name)&alt=json

How to pass this slot in the request url correctly?

solved

        response = service.files().list(q='(name contains \'{0}\')'.format(a),
                                          spaces='drive',
                                          fields='nextPageToken, files(id, name)',
                                          pageToken=page_token).execute()