error: [Error 32] Broken pipe——造成此错误的一种可能原因及解决方法

目标:异步调用——前端用jQuery Ajex中的get()方法请求服务器上的json数据,并显示在页面上。

错误显示如下:

10.10.10.252 - - [15/Aug/2018 19:59:09] "GET /cadastreSearch?level=15 HTTP/1.1" 200 -
----------------------------------------
Exception happened during processing of request from ('10.10.10.252', 35198)
Traceback (most recent call last):
  File "/usr/lib64/python2.7/SocketServer.py", line 593, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib64/python2.7/SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib64/python2.7/SocketServer.py", line 651, in __init__
    self.finish()
  File "/usr/lib64/python2.7/SocketServer.py", line 710, in finish
    self.wfile.close()
  File "/usr/lib64/python2.7/socket.py", line 279, in close
    self.flush()
  File "/usr/lib64/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe

错误描述:定义了标签<a>Process 1</a>的click事件,页面加载完成后点击"Process 1"来调用$.get()函数,页面会被刷新,且没有数据被显示。通过调试,发现$.get(url, data,function,datatype)执行成功,且服务器会返回Response Header,其中显示“200 OK”。但是再往下执行页面就会刷新,所有资源被重新加载,后台服务器报错(如上所示)。

出错的原因:使用了标签<a> 来绑定“click”事件,至于为什么点击<a>会导致页面的刷新具体原因还未清楚。

解决方法:改用标签<button>或其他不会刷新页面的标签。

参考资料:https://blog.csdn.net/zsdt345a780rfajwet/article/details/72828816

                  https://bbs.csdn.net/topics/390786750

第一篇文章中的方法我其实已经加在python代码中了,并没有起作用。因为同样是Broken Pipe错误(客户端在服务器返回前,就已经断开连接,服务器端写response才报错),我的是因为页面刷新,导致之前的连接断开,她的原因就是单纯Ajex跨域吧。

第二个链接才是真正启发我找到错误原因和解决方法的。

最后,附上代码:

<script>
	$(function(){
		init();
	});
	$(function () {
		$("button[name='process1']").click(function () {
		    alert("click on the process1 entry!")

            $.get(url + '/cadastreSearch', {
                level: map.getZoom()

            }, function (data) {
                redline = L.geoJSON(data[0], {
                    color: 'red',
                    onEachFeature: onEachFeature
                });
                map.addLayer(redline);
                freehold = L.geoJSON(data[1], {
                    color: 'blue',
                    onEachFeature: onEachFeature
                });
                map.addLayer(freehold);
                usedlandrl = L.geoJSON(data[2], {
                    color: 'green',
                    onEachFeature: onEachFeature
                });
                map.addLayer(usedlandrl);
                console.log(data[2]);
            }, "json");
        })
    })
	$(function(){
		layershow();
	});
	</script>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值