我正在尝试创建一个程序,可以分析终端中网站的速度。我使用curl模块在Linux shell中处理该命令。但我得到了以下错误
ValueError: unsupported format character '{' (0x7b) at index 40
import subprocess
def webSpeed():
website = raw_input("Enter name of the website: ")
print(website)
cmd = "curl -s -w 'Website Response Time for :%{url_effective}\n\nLookup Time:\t\t%{time_namelookup}\nConnect Time:\t\t%{time_connect}\nAppCon Time:\t\t%{time_appconnect}\nRedirect Time:\t\t%{time_redirect}\nPre-transfer Time:\t%{time_pretransfer}\nStart-transfer Time:\t%{time_starttransfer}\n\nTotal Time:\t\t%{time_total}\n' -o /dev/null https://%s" %(webiste)
print(cmd)
temp = subprocess.call(cmd, shell="TRUE")
print(temp)
如果python使用大括号,如何在python中添加curl命令
当你这样做的时候
然后将字符串中的每个
%
视为格式化位置。Python发现了%{
并感到困惑-它期望%d
用于放置整数,或者%s
用于放置字符串,或者其他它知道的东西。但是格式化代码不会对任何格式使用%{
,因此是错误的。当您想要写入没有格式含义的%
时,您应该通过另一个%
对其进行转义因此,有两种解决办法
%%
更改所有(最后一个%s
除外)string % format_values
,只需将网站添加到 你的命令已经结束了正确和错误的代码示例:
相关问题 更多 >
编程相关推荐