python subprocess.Popen() error -
def run_mitmdump(basename, timeout, logging=false): port = get_free_port() print(port) if not port: # cannot free port return none, none dump_file = "%s.dmp" % basename cmd_re_dir = '' # redirecting stderr stdout , teeing quite_option = '-q' # mitmdump option quiet - no log if logging: mitm_log_file = "%s.%s" % (basename, mitm_log_extension) cmd_re_dir = ' 2>&1 |tee %s' % mitm_log_file # redirect output log file quite_option = '' # don't want quite! cmd = 'timeout %s mitmdump %s -z --anticache -p %s -w %s %s' % (timeout, quite_option, port, dump_file, cmd_re_dir) # -z: try convince servers send uncompressed data. mitmdump -h | grep "\-z" info wl_log.info('mitmdump cmd %s' % cmd) subp = subprocess.popen(cmd, shell=true) # shell=true - must careful return port, subp.pid def init_mitmproxy(basename, timeout, logging): try: port, pid = run_mitmdump(basename, timeout + 1, logging) # runs mitmdump process timeout+1 sec except: wl_log.critical('exception initializing mitmdump') else: wl_log.info('mitmdump listen on port %s, pid %s' % (port, pid)) print(port) return "127.0.0.1:%s " % port if port , pid else ""
when program executed subprocess.popen(cmd,shell=true)
error occurred , print('abc')、"return port,subp.pid" not performed。 there no return value in second function port, pid = run_mitmdump(basename, timeout + 1, logging)
the error message is:
2017-08-20 19:17:39,428 - error - exception in worker function (362,'wideinfo.org') local variable 'port' referenced before assignment traceback (most recent call last): file "agents.py", line 212, in crawl_worker proxy_opt = mitm.init_mitmproxy(stdout_log[:-4], agent_cfg['timeout'], agent_cfg['mitm_proxy_logs']) if agent_cfg['use_mitm_proxy'] else "" file "/home/vagrant/fpdetective/src/crawler/mitm.py", line 85, in init_mitmproxy print(port) unboundlocalerror: local variable 'port' referenced before assignment
Comments
Post a Comment