Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XML Parsing Child
#1
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!
Reply


Messages In This Thread
XML Parsing Child - by karthi_python - May-16-2019, 11:45 AM
RE: XML Parsing Child - by karthi_python - May-16-2019, 01:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using one child class method in another child class garynewport 5 1,612 Jan-11-2023, 06:07 PM
Last Post: garynewport
  parent/add and child/div PyMan 1 2,423 Feb-23-2018, 04:38 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020