0

Im trying to read the server names(eg: server1) in a variable and pass it to a url. However, url doesnt take the variable but only the server name hardcoded in it.

Is there any way for me to accomplish this?

 def connect_to_BNAserver(BNAserver):
   connection = http.client.HTTPConnection(BNAserver)
   baseurl="'https://"+BNAserver+"/rest/login'"
   header = {"WSUsername": BNAUser, "WSPassword": BNAPass,"Accept": "application/vnd.brocade.networkadvisor+json;version=v1"}

   connection.request('POST',BaseUrl,headers=header)  

The below works:

   header = {"WSUsername": BNAUser, "WSPassword": BNAPass,"Accept": "application/vnd.brocade.networkadvisor+json;version=v1"}

   connection.request('POST','https://server1/rest/login',headers=header)
Barmar
  • 741,623
  • 53
  • 500
  • 612
Manu SS nair
  • 25
  • 2
  • 7

1 Answers1

0

First variable names are case sensitive.

Second, you shouldn't put quotes in the URL (you don't have them in the working case).

def connect_to_BNAserver(BNAserver):
   connection = http.client.HTTPConnection(BNAserver)
   baseurl="https://"+BNAserver+"/rest/login"
   header = {"WSUsername": BNAUser, "WSPassword": BNAPass,"Accept": "application/vnd.brocade.networkadvisor+json;version=v1"}

   connection.request('POST',baseurl,headers=header)  
Barmar
  • 741,623
  • 53
  • 500
  • 612