我尝试使用格式& +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)发布于 2019-07-10 20:53:41
在第一部分中,您的有效负载是一个字符串,而不是一个字典,它应该是
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函数。
https://stackoverflow.com/questions/56970207
复制相似问题