我正在尝试使用格式&+ str(Var)+将多个变量传递给有效负载,但没有得到预期的输出。我在文件中有主机名,并输入密码作为输入并将其传递给有效负载。
我遇到与"Error while parsing JSON payload or an incompatible argument type for the requested resource"
相关的错误
for x in content:
url='https://url/a/b/c/{}'.format(x.strip())
payload=('{{"ip-address": "x.x.x.x","user-name": "john","password": "'+ str(Pass) +'","db-name": "'+ str(x.strip()) +'","service-name": "y","port": "y","connection-string": "y"}}')
response = req.post(url,json=payload,headers=add_cookie,verify=False)
======================
for x in content:
url='https://url/a/b/c/{}'.format(x.strip())
payload={"ip-address": "x.x.x.x","user-name": "john","password": "{}","db-name": "{}","service-name": "y","port": "y","connection-string": "y"}.format(Pass, x.strip())
response = req.post(url,json=payload,headers=add_cookie,verify=False)
答案 0 :(得分:0)
第一部分,您的有效载荷是字符串而不是字典,应该是
payload={"ip-address": "x.x.x.x","user-name": "john","password": str(Pass),"db-name": str(x.strip()),"service-name": "y","port": "y","connection-string": "y"}
在第二种方法中,您对错误的dict类型使用了format函数。