我有一个简单的python脚本,当我尝试动态添加IP时,requests.get
总是给我带来问题
如果我这样做,它会起作用:
r = requests.get("http://123.123.123.123")
如果我这样做,它就会失败:
r = requests.get("http://" + ipnum)
这是完整的代码
#!/usrbin/env python
import subprocess
import requests
ipnum = subprocess.check_output(["hostname", "-i"])
ipstr = str(ipnum)
r = requests.get ("http://" + ipstr)
if r.status_code == 200
print("Web1:"+ str(r))
else:
print("Web1:"+ str(r))
当我进行测试时,我发现
check_output
在末尾添加了一个新行。将ipstr.strip()
添加到“http://”时,请尝试使用ipstr
而不是ipstr
相关问题 更多 >
编程相关推荐