-1

I've below code in python to connect to HP QC ALM and it's working as expected when values are hardcoded:

from win32com.client import Dispatch
class QC_ConnectorClass(object):
def __init__(self):
    print("class init")

def ConnectToQC(self):
    #HP QC OTA methods
    self.TD = Dispatch("TDApiOle80.TDConnection.1")
    self.TD.InitConnectionEx("http://hpqcurl.org")
    self.TD.Login("UName","Pwd")
    self.TD.Connect("Domain","project")
    if self.TD.Connected == True:
        print("Logged in")
        self.TD.Logout();
        print("Logged out")
        self.TD.ReleaseConnection();
    else:
        print("Login failed")

On passing hp qc url to variable like

hpQCURL="http://hpqcurl.org" 

and pass the variable like this:

self.TD.InitConnectionEx(hpQCURL)

I receive the following error:

File "<COMObject TDApiOle80.TDConnection.1>", line 2, in InitConnectionEx
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147023174), None)
2
  • Can someone tell me why it is downvoted? Commented Nov 27, 2018 at 12:19
  • I still wonder that why question is downvoted? Commented Nov 27, 2018 at 13:11

1 Answer 1

3

from win32com.client import Dispatch
class QC_ConnectorClass(object):
    var = "http://hpqcurl.org"
    def __init__(self):
        print("class init")    
    def ConnectToQC(self):
        #HP QC OTA methods
        self.TD = Dispatch("TDApiOle80.TDConnection.1")
        self.TD.InitConnectionEx(QC_ConnectorClass.var)
        self.TD.Login("UName","Pwd")
        self.TD.Connect("Domain","project")
        if self.TD.Connected == True:
            print("Logged in")
            self.TD.Logout();
            print("Logged out")
            self.TD.ReleaseConnection();
        else:
            print("Login failed")

Worked for me, but you can also initialize the variable globally outside the scope of the class. In this case I defined a static variable, that's why I need to call it in this way: QC_ConnectorClass.var But take a look on this answer to understand the importance of the position of the initialization (correct way to define class variables in Python)

Sign up to request clarification or add additional context in comments.

2 Comments

is there a way I can declare empty var and get the config value from .ini file on init and pass the same in ConnnectToQC?
I found your answer helpful. I made a mistaken in .ini file. Since I am from .Net background, I pass values inside double quotes. So, I had like url="http://url.org" in .ini file. Actually, double quotes not required and has to be like url=http://url.org. It's fixed now. Thanks! Welcome to Stackoverflow!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.