我正在尝试读取变量中的服务器名称(例如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)
答案 0 :(得分: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)