Python Forum
C# to Python help - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: C# to Python help (/thread-9506.html)



C# to Python help - SniperPro - Apr-13-2018

Hello

I want to write this same code in c# on python code :

var generateTokenRequestParameters = new GenerateTokenRequest("View", null, identities: new List<EffectiveIdentity> { new EffectiveIdentity(username: "myUserName", roles: new List<string> { "FranceSales" }, datasets: new List<string> { "382ea16c-fbcc-4cec-bb60-470aff4aebaa" }) });
Any help ?


RE: C# to Python help - Larz60+ - Apr-13-2018

Since that is a C# for Azure command, suggest you start here: https://docs.microsoft.com/en-us/python/azure/?view=azure-python

also see: https://pypi.python.org/pypi?%3Aaction=search&term=azure&submit=search


RE: C# to Python help - SniperPro - Apr-17-2018

Thank you for your reply, this is good but if some one could help me saving time it would be better :)

this is my python code :
class EmbedToken:
    def __init__(self, report_id, group_id, settings=None):
        self.username = '[email protected]'
        self.password = 'MyPassword'
        self.client_id = '28c7e68d-6eb1-4be3-8b97-4c0fa9cd83d6'
        self.report_id = report_id
        self.group_id = group_id
        if settings is None:
            #self.settings = {'accessLevel': 'View', 'allowSaveAs': 'false'}
            self.identitie = {'accessLevel': 'View','identities': [{'username': '[email protected]','roles': ['FranceSales'],'datasets': ['382ea16c-fbcc-4cec-bb60-470aff4aebaa']}]}
            print(self.identitie)
            self.settings = self.identitie
        else:
            self.settings = settings
When I add identities to json settings it's not working .


RE: C# to Python help - Larz60+ - Apr-17-2018

you should encrypt first, then save as json
This code not tested, but should work or only need minor modification.
at top:
import json
after line 14:

        self.save_settings(filename)

def save_settings(self, filename):
    with filename.open('w') as f:
        json.dump(self.settings, f)

# for reading back in:
def load_file(self, filename):
    with filename.open('r') as f:
        self.settings = json.load(f)