我将Web服务器放在具有公共IP的远程计算机上时出现问题,当我尝试在服务器上调用某个函数时出现此错误: (我试图将同一台服务器放在本地的虚拟机上并且有效)
> Traceback (most recent call last): File
> "/usr/lib/python2.6/wsgiref/handlers.py", line 94, in run
> self.finish_response() File "/usr/lib/python2.6/wsgiref/handlers.py", line 135, in finish_response
> self.write(data) File "/usr/lib/python2.6/wsgiref/handlers.py", line 223, in write
> self._write(data) File "/usr/lib/python2.6/socket.py", line 300, in write
> self.flush() File "/usr/lib/python2.6/socket.py", line 286, in flush
> self._sock.sendall(buffer) error: [Errno 104] Connection reset by peer
客户端应用
(urls.py文件):
urlpatterns = patterns('',
(r'^time/$', current_datetime),
(r'^time/remoteserverIP:8000/api/comp/$', comp),
(views.py文件):
def comp(request):
encoded_data = urllib.urlencode(request.POST)
url = urllib2.urlopen('http://remoteserverIP:8000/api/comp/?' + encoded_data)
tml = url.read()
return HttpResponse(tml)
(index.html文件):
<form id="codeid" method="post" enctype="application/x-www-form-urlencoded" name="code" action="remoteserverIP:8000/api/comp/">
<textarea id="textarea_1" name="content" cols="80" rows="15" type="text" onkeypress="return runScript(event)"></textarea>
<input id="thebutton" type="button" value="Submit" onclick="document.forms.codeid.submit();" />
</form>
服务器端应用:
函数调用:
def compile(request):
data2=urllib.urlencode({'': request.GET.get('content','')})
request.encoding ='koi8-r'
data=request.GET.get('content','')
handle=open('/homedir/file.c','r+')
handle.write(request.GET['content'])
handle.close()
return HttpResponse(commands.getstatusoutput('gcc -Wall /homedir/file.c -o /homedir/file;/homedir/file;'))