相关疑难解决方法(0)

在调试模式下Django Broken管道

我在Nginx后面的远程服务器上有django 1.3.

如果我用apache + mod_wsgi运行django,我可以在apache日志文件中查看错误.没关系,但我想要在控制台中.

如果我运行django自己的开发服务器,只有在DEBUG = False时才会在控制台中出现stacktrace错误.在DEBUG模式控制台输出中

Exception happened during processing of request from (..., ...)
Traceback (most recent call last):
  File "/usr/local/python/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/local/python/lib/python2.7/SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "/usr/local/python/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/local/python/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 570, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "/usr/local/python/lib/python2.7/SocketServer.py", line 641, in __init__
    self.finish()
  File "/usr/local/python/lib/python2.7/SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "/usr/local/python/lib/python2.7/socket.py", line 301, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] …
Run Code Online (Sandbox Code Playgroud)

django broken-pipe

48
推荐指数
3
解决办法
4万
查看次数

如何在python中处理损坏的管道(SIGPIPE)?

我在python中编写了一个简单的多线程游戏服务器,为每个客户端连接创建一个新线程.我发现时不时,服务器会因为管道损坏/ SIGPIPE错误而崩溃.当程序试图将响应发送回不再存在的客户端时,我非常确定它正在发生.

处理这个问题的好方法是什么?我的首选解决方案只是关闭与客户端的服务器端连接并继续,而不是退出整个程序.

PS:这个问题/答案以一般方式处理问题; 具体应该如何解决?

python broken-pipe

47
推荐指数
2
解决办法
8万
查看次数

收到 BrokenPipeError:[Errno 32] 发送第二个套接字 MSG 时管道损坏

我正在尝试使用套接字将指令从 Django 网站发送到机器人(Raspberry Pi),但每当我尝试从网站发送第二条指令时,都会出现错误。如果您知道造成此问题的原因,那么帮助将是惊人的!网站发送查看:

def form_valid(self, form, **kwargs):
        robo_pk = self.kwargs['pk']
        robo = Robot.objects.get(pk=robo_pk)
        PORT = robo.port
        SERVER = robo.server
        ADDR = (SERVER, PORT)
        self.object = form.save()
        client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        client.connect(ADDR)

        def send(msg):
            message = msg.encode(FORMAT)
            msg_length = len(message)
            send_length = str(msg_length).encode(FORMAT)
            send_length += b' ' * (HEADER - len(send_length))
            client.send(send_length)
            client.send(message)

        send(form.cleaned_data['path_options'])
        send("MESSAGE SENT :) !")
        send(DISCONNECT_MESSAGE)
        return render(self.request, "dashboard-home/thank-you.html")
Run Code Online (Sandbox Code Playgroud)

错误回溯:

Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in …
Run Code Online (Sandbox Code Playgroud)

python sockets networking python-3.x raspberry-pi

7
推荐指数
1
解决办法
2809
查看次数

浏览器在完全下载响应之前关闭套接字

我有一个简单的Python服务器使用http.server.目标不是在html页面中显示视频,也不是下载视频文件,而是直接在浏览器中显示视频.这是我到目前为止:

import http.server

class SuperHandler(http.server.SimpleHTTPRequestHandler):
    def do_GET(self):
        path = self.path
        encodedFilePath = 'file.mp4'

        with open(encodedFilePath, 'rb') as videoFile:
            self.send_response(200)
            self.send_header('Content-type', 'video/mp4')
            self.end_headers()
            self.wfile.write(videoFile.read())
            print('File sent: ' + videoFile.name)

server_address = ('', 8000)
handler_class = SuperHandler
httpd = http.server.HTTPServer(server_address, handler_class)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是响应不包含完整视频.file.mp4是50MB,但当我查看Chrome或Firefox的网络选项卡时,它表示响应只有1MB.有没有理由不传输完整文件?我是否需要添加某种HTTP标头才能使其正常工作?

编辑:

这是我现在的代码:

server_address = ('', 8000)
handler_class = http.server.SimpleHTTPRequestHandler
httpd = http.server.HTTPServer(server_address, handler_class)

httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)

我现在使用的是默认的SimpleHTTPRequestHandler do_GET,但它仍然无法正常工作(尽管响应现在是40MB/30MB而不是1MB).

当我file.mp4在Chrome上请求时,套接字连接在大约7秒后关闭(在Firefox上大约5秒),这使得脚本抛出一个BrokenPipeError: [Errno 32] Broken pipe,因为服务器仍在尝试将其余的视频文件写在已关闭的套接字上.

所以我的问题是:如何让浏览器在关闭套接字之前下载完整的响应?

附加信息

发送到客户端的HTTP响应标头:

HTTP/1.0 200 OK
Server: …
Run Code Online (Sandbox Code Playgroud)

python firefox google-chrome http http-headers

6
推荐指数
1
解决办法
526
查看次数

使用Bottle框架的Python粘贴破坏管道错误

我正在使用实现WSGI请求和响应的Bottle框架,并且由于单线程问题,我将服务器更改为PythonWSGIServer并使用Apache bench进行测试但结果包含错误中断管道,这与此问题类似如何防止errno 32中断管?.我已经尝试了答案但无济于事.

  Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/paste/httpserver.py", line 1068, in process_request_in_thread
    self.finish_request(request, client_address)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 641, in __init__
    self.finish()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
Run Code Online (Sandbox Code Playgroud)

服务器代码如下所示,我不知道如何使用线程池改善连接?

from paste import httpserver

    @route('/')
    def index():
        connection = pymongo.MongoClient(connectionString)
        db = connection.test
        collection = db.test
        return str(collection.find_one())

    application = default_app()
    httpserver.serve(application, host='127.0.0.1', port=8082)
Run Code Online (Sandbox Code Playgroud)

python paste

5
推荐指数
1
解决办法
1854
查看次数

socket.error:[Errno 32]管道破裂

我写了一个客户端 - 服务器python程序,客户端向服务器发送一个列表,服务器接收数组,删除列表的前两个元素并将其发送回客户端.接收列表的服务器没有问题.但是当服务器想要发回已编辑的列表时,它显示错误: socket.error: [Errno 32] Broken pipe.client.py和server.py是从具有不同ip的不同计算机运行的.我正在发布下面的client.py和server.py的代码:

Client.py

import socket, pickle
HOST = '192.168.30.218'
PORT = 50010
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
arr = ['CS','UserMgmt','AddUser','Arnab','Password']
data_string = pickle.dumps(arr)
s.send(data_string)
data = s.recv(4096)
data_arr1 = pickle.loads(data)
s.close()
print 'Received', repr(data_arr1)
print data_arr1;
Run Code Online (Sandbox Code Playgroud)

Server.py:

import socket, pickle;
HOST = '127.0.0.1';
PORT = 50010;
s= socket.socket(socket.AF_INET, socket.SOCK_STREAM);
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1);
s.bind(('',PORT));
s.listen(1);
conn, addr = s.accept();
print 'Connected by' , addr;
data_addr = list();
while 1:
        data = conn.recv(4096);
        if …
Run Code Online (Sandbox Code Playgroud)

python sockets network-programming python-2.7

5
推荐指数
1
解决办法
3万
查看次数

断管错误硒webdriver,当命令之间有差距?

Ubuntu 18.x + selenium webdriver(Firefox)

面对一个奇怪的问题,如果我run将它们全部放在一起,下面的块就可以工作了

from selenium import webdriver
url = 'https://indiamart.com'
driver = webdriver.Firefox()
driver.get(url)
driver.find_element_by_xpath(xpath).click()
Run Code Online (Sandbox Code Playgroud)

每次url尝试过都会发生这种情况.

但是,如果我一次执行一行,它会给出

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 326, in get
    self.execute(Command.GET, {'url': url})
  File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 472, in execute
    return self._request(command_info[0], url, body=data)
  File "/media/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 495, in _request
    self._conn.request(method, parsed_url.path, body, headers)
  File "/usr/lib/python3.6/http/client.py", line 1239, in request …
Run Code Online (Sandbox Code Playgroud)

python ubuntu selenium selenium-webdriver

5
推荐指数
2
解决办法
2412
查看次数