Python Forum

Full Version: XML Parsing Child
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
All,

Good Evening! I'm newbie to Python and this is my first post here.

I am a tableau developer where i have to write a python script to get all the permissions of all the worksheets. I found some script in GITHUB and tried to modify, but i'm failed due to lack of experience in python. So i thought of seeking help from here.

Sample XML :

Sample Expected Output Format:
Output:
UserId Name Mode 1 Read Allow 1 Write Allow 2 Read Allow 2 ShareView Allow
I can see below the packages are used in the script.

from version import Version
import requests # Contains methods used to make HTTP requests
import xml.etree.ElementTree as ET # Contains methods used to build and parse XML
import sys
import getpass
import math
My Code:

def query_permission(server, auth_token, site_id):
    """
    Returns a list of all permissions for the specified user.
    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    'workbook_id'   ID of workbook to update permission in
    'user_id'       ID of the user to update
    """
    url = server + "/api/3.3/sites/{0}/workbooks/{1}/permissions".format( site_id, '82cbe061-81c0-49ca-b376-bc893452760b')
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token},verify=False)
    _check_status(server_response, 200)
    server_response = _encode_for_display(server_response.text)

    # Reads and parses the response
    parsed_response = ET.fromstring(server_response)

    # Find all the capabilities for a specific user
    capabilities = parsed_response.findall('.//t:granteeCapabilities', namespaces=xmlns)
    for capability in capabilities:
        user_tag = capability.find("user")#, namespaces=xmlns)
        #users = [(user.get('id')) for user in user_tag]
        users = user_tag.attribute("id")
        print ("%s", users)
 #   return users 
#, capability.findall('.//t:capability', namespaces=xmlns)
But the code is not giving expected result...

Any help is highly appreciable!
any inputs are highly appreciable! I know this is not paid forum, volunteers will reply based on their availability...

But it is bit urgent..so some push from my side...