返回的非零退出状态3 python2.7子进程check_output

问题描述:

我已经写了一些python代码,使得执行curl命令的子进程调用,但是我得到一个错误Command '['sh', '/tests/curlhttp.sh', 'http://www.bbc.co.uk', '80']' returned non-zero exit status 3我也尝试通过终端运行该命令我的linux的盒子,这似乎是好的。这里是我的Python脚本返回的非零退出状态3 python2.7子进程check_output

def RunCURL(command): 
    result = [] 
    //I get an error when running this 
    output = check_output(command.split(" "), stderr=subprocess.STDOUT) 
    print output 
    # loop through and create a list of lists 
    for line in output.splitlines(): 
     if "=" in line and "time_total" not in line: 
      sublist = line.split("=")[0].rstrip().lstrip() 
      print sublist + " hello this is curl" 
      result.append(sublist) 
    return result 

,这里是我的卷曲脚本我试图执行:

#!/bin/bash 
curl -w '\ncontent_type=%{content_type}\nfilename_effective=%{filename_effective}\nftp_entry_path=%{ftp_entry_path}\nhttp_code=%{http_code}\nhttp_connect=%{http_connect}\nlocal_ip=%{local_ip}\nlocal_port=%{local_port}\nnum_connects=%{num_connects}\nnum_redirects=%{num_redirects}\nredirect_url=%{redirect_url}\nremote_ip=%{remote_ip}\nremote_port=%{remote_port}\nsize_download=%{size_download}\nsize_header=%{size_header}\nsize_request=%{size_request}\nsize_upload=%{size_upload}\nspeed_download=%{speed_download}\nspeed_upload=%{speed_upload}\nssl_verify_result=%{ssl_verify_result}\ntime_appconnect=%{time_appconnect}\ntime_connect=%{time_connect}\ntime_namelookup=%{time_namelookup}\ntime_pretransfer=%{time_pretransfer}\ntime_redirect=%{time_redirect}\ntime_starttransfer=%{time_starttransfer}\ntime_total=%{time_total}\nurl_effective=%{url_effective}\n\n' -o /dev/null -s $1:$2 

我从这个博客采取这一卷曲脚本,并只改变了脚本中的地址栏接受URL和端口号:http://blog.kenweiner.com/2014/11/http-request-timings-with-curl.html

这是我得到的运行从博客本身复制的卷曲脚本时直入终端

content_type=text/html; charset=UTF-8 
filename_effective=/dev/null 
ftp_entry_path= 
http_code=302 
http_connect=000 
local_ip=10.250.8.99 
local_port=60839 
num_connects=1 
num_redirects=0 
redirect_url=https://www.google.co.uk/?gfe_rd=cr&ei=_7gdWOrCLrH38Af1qoKIBw 
remote_ip=216.58.204.36 
remote_port=443 
size_download=262 
size_header=258 
size_request=78 
size_upload=0 
speed_download=3535.000 
speed_upload=0.000 
ssl_verify_result=0 
time_appconnect=0.062 
time_connect=0.013 
time_namelookup=0.001 
time_pretransfer=0.062 
time_redirect=0.000 
time_starttransfer=0.074 
time_total=0.074 
url_effective=https://www.google.com/ 

当我把这个脚本到一个文件中我得到这个

content_type= 
filename_effective=/dev/null 
ftp_entry_path= 
http_code=000 
http_connect=000 
local_ip= 
local_port=0 
num_connects=0 
num_redirects=0 
redirect_url= 
remote_ip= 
remote_port=0 
size_download=0 
size_header=0 
size_request=0 
size_upload=0 
speed_download=0.000 
speed_upload=0.000 
ssl_verify_result=0 
time_appconnect=0.000 
time_connect=0.000 
time_namelookup=0.000 
time_pretransfer=0.000 
time_redirect=0.000 
time_starttransfer=0.000 
time_total=0.000 
url_effective=https://www.google.com/ 

cUrl error codes看它看起来像3意味着您的网址是的malformatted。当你在Python之外运行它时它工作吗?

+0

我从博客复制并粘贴了curl脚本,然后运行该脚本,它就起作用了。然而,当我复制并将其粘贴到shell文件时,它似乎没有给我任何信息,除了标签。我已经编辑了我的帖子,以包含预期的输出与我从被称为sh命令放置在文件中的curl脚本获得的输出 – DorkMonstuh