[Python] Specify the display language for Office365-REST-Python-Client in Python for...

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I try to load data from a Sharepoint list using Office365-REST-Python-Client package in Python.

    A site collection is created with a default language e.g. English which cannot be changed afterwards. And if multi-language is activated on the sitecollection, a user can login with e.g. German and is able to create objects with display language in German.

    I can successfully connect via a defined app (with Client ID and Secret) to my Sharepoint Online using Office365-REST-Python-Client package in Python.

    The Python Scripts connects and uses the default language - e.g. English. So I don't have a chance to load the display names in German.

    I have tried to change the language via the header:

    from office365.sharepoint.client_context import ClientContext
    from office365.runtime.http.request_options import RequestOptions

    # SharePoint-URL und Authentifizierungsdetails
    site_url = "https://site"
    client_id = "clientid"
    client_secret = "secret"

    credentials = ClientCredential(client_id, client_secret)
    ctx = ClientContext(site_url).with_credentials(credentials)

    # Sprache auf Deutsch setzen
    request = RequestOptions(ctx.service_root_url)
    request.ensure_header("Accept-Language", "de-DE") # Sprachpräferenz einstellen



    # Abfrage der Listen
    lists = ctx.web.lists.get().execute_query()

    # Displaynamen der Listen ausgeben
    for sp_list in lists:


    But the Displayname like "listnames, fieldnames" (Title) are still returned in English. In general the request should be dynamic, because some site-collections are in English, others are in German. Therefore it's important to set the language in the Python script so the right display names are returned.

    So how can the language in the REST API be set?

    Continue reading...

Compartilhe esta Página