我正在尝试编写python脚本以登录到我的服务器之一并进行一些检查。为此,我想将我的网址,用户名和密码传递给script。 类似于script.py 1.1.1.2 admin admin。我想在脚本中使用 IP , USERNAME 和 PASSWORD 。我可以将其用作打印IP?使用下面的方法会收到证书错误
> File "/usr/lib/python2.6/site-packages/redfish/rest/v1.py", line
> 1064, in login
> raise InvalidCredentialsError(delay) redfish.rest.v1.InvalidCredentialsError: 10
这是我的剧本
import sys
from _restobject import RestObject
IP = sys.argv[1]
USERNAME = sys.argv[2]
PASSWORD = sys.argv[3]
def ex3_change_bios_setting(restobj, bios_property, property_value, \
):
sys.stdout.write("\nEXAMPLE 3: Change a BIOS setting\n")
instances = restobj.search_for_type("HpBios.")
for instance in instances:
body = {bios_property: property_value}
response = restobj.rest_patch(instance["href"], body, \
)
restobj.error_handler(response)
if __name__ == "__main__":
iLO_https_url = "https://"+ IP +""
iLO_account = PASSWORD
iLO_password = USERNAME
#Create a REST object
REST_OBJ = RestObject(iLO_https_url, iLO_account, iLO_password)
ex3_change_bios_setting(REST_OBJ, "InternalSDCardSlot", "Disabled")
答案 0 :(得分:1)
您可以通过+
运算符在python中将字符串与硬编码值连接起来。
试试这个代码。很好。
IP = sys.argv[1]
USERNAME = sys.argv[2]
PASSWORD = sys.argv[3]
iLO_https_url = "https://"+ IP +""
iLO_account = PASSWORD
iLO_password = USERNAME