0

我试图读取变量中的服务器名称(例如:server1)并将其传递给 url。但是, url 不接受变量,而只接受硬编码的服务器名称。

我有什么办法可以做到这一点吗?

 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)  

以下作品:

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

   connection.request('POST','https://server1/rest/login',headers=header)
4

1 回答 1

0

第一个变量名区分大小写。

其次,您不应该在 URL 中加上引号(在工作案例中没有引号)。

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)  
于 2019-03-04T19:46:42.073 回答