pyOpenSSL SSL3_WRITE_PENDING:错误的写入重试,返回self._sslobj.write(data)错误:[Errno 10054] [英] pyOpenSSL SSL3_WRITE_PENDING:bad write retry, return self._sslobj.write(data) error: [Errno 10054]

查看:296
本文介绍了pyOpenSSL SSL3_WRITE_PENDING:错误的写入重试,返回self._sslobj.write(data)错误:[Errno 10054]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在用Python开发聊天服务器. 我正在将pyOpenSSL应用于我为测试而创建的聊天服务器和虚拟客户端. 但是,每当从虚拟客户端向服务器发送文本消息和照片文件时,pyOpenSSL都会返回重大错误,这驱使我停止使用pyOpenSSL,如下所示.

I'm now developing a chatting server in Python. I am in the middle of applying pyOpenSSL to the chatting server and dummy clients which I made for testing. But whenever sending text messages and photo file from dummy clients to the server, pyOpenSSL returns significant error which drives me to stop using pyOpenSSL like below.

send_text_message() : exception : [Errno 1] _ssl.c:1309: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
send_text_message() : exception : [Errno 1] _ssl.c:1309: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
send_text_message() : exception : [Errno 1] _ssl.c:1309: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
send_text_message() : exception : [Errno 1] _ssl.c:1309: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
send_text_message() : exception : [Errno 1] _ssl.c:1309: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
send_text_message() : exception : [Errno 1] _ssl.c:1309: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
send_text_message() : exception : [Errno 1] _ssl.c:1309: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry

能否让我知道如何解决该错误? 还有一个错误导致虚拟客户端死亡.

Could you let me know how to solve the error? there's one more error which causes dummy client to die.

[client1|chatting1A] socket closed : device_id : client1, client_chatting_id : chatting1A, error : [Errno 10053] 
Exception in thread Thread-8:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 1082, in run
    self.function(*self.args, **self.kwargs)
  File "D:\temp\uTok1\uTokSocketServer\com\rurusoft\utok\DummyClient.py", line 97, in send_photo_message
    sock.write(message)
  File "C:\Python27\lib\ssl.py", line 172, in write
    return self._sslobj.write(data)
error: [Errno 10054]

没有pyOpenSSL,虚拟客户端和服务器可以正常工作.应用pyOpenSSL会导致意外的问题:(. 如果您遇到问题或有解决问题的方法,请告诉我. ....如果没有解决该错误的方法,我宁愿找出其他不使用OpenSSL的替代方法. 还是您知道可以加密/解密聊天消息和机器之间传输的个人文件的任何替代品?

Without pyOpenSSL, dummy clients and the server work well. Applying pyOpenSSL causes unexpected problems :(. If you have encountered the problems or have solutions to the problems, please let me know. .... If there's no solutions to the error, I'd rather find out other alternatives not using OpenSSL.. Or do you know any alterntives which can encrypt/decrypt chatting messages and personal files transfered between machines?

尽管我已经在写入(发送)数据之前将数据存储在本地变量中,但每次都会发生错误.


  json_encoded = json.dumps(data)
          while True:
              try:
                  sock.write(json_encoded)
                  break
              except Exception, e:
                  Log.print_log(self.LOG_TAG, 'send_text_message() : exception : %s' % (e))
                  time.sleep(0.05)

已解决: 正如@David Schwartz所评论的那样,以下代码解决了上面的问题.

Solved : As @David Schwartz commented, the following codes solved the upper issues.

    import StringIO
    ...
    io = StringIO.StringIO()
    io.write(json.dumps(data))
    buffer = io.getvalue()
    while True:
        try:
            sock.write(buffer)
            break
    ...
    

推荐答案

OpenSSL对如何重试写入有非常严格的要求-特别是不得更改缓冲区的地址和内容.重试写入时,必须使用 exact 相同的缓冲区重试(相同的内容是不够的,当然,绝对禁止使用不同的内容).

OpenSSL has very strict requirements about how writes can be retried -- specifically the buffer's address and contents must not be changed. When you retry a write, you must retry with the exact same buffer (the same contents are not sufficient and, of course, different contents is absolutely prohibited).

例如,它已损坏:

ssl_socket.send(send_buffer.getvalue())

由于您没有存储传递给send的值,因此,如果您需要重试send,如何将相同的值传递给它?无法保证随后对getvalue的调用将返回相同的结果.如果缓冲区移动,重复执行此操作可能会导致错误的写入重试.

Since you didn't store the value you passed to send, if you need to retry the send, how can you pass it the same value? There's no guarantee a subsequent call to getvalue will return the same result. Repeating this operation can generate a bad write retry if the buffer moves, which it can at any time.

更新:您的代码无法阻止缓冲区更改.没有不会改变的对象反映了缓冲区.试试:

Update: Your code does nothing to prevent the buffer from changing. There is no object that does not change that reflects the buffer. Try:

io = StringIO()
json.dumps(data, io)
buffer = io.getvalue()

      while True:
          try:
              sock.write(buffer)
              break

在这里,io是缓冲区,并且仅在其上调用getvalue.

Here, io is the buffer, and getvalue is called on it only once.

这篇关于pyOpenSSL SSL3_WRITE_PENDING:错误的写入重试,返回self._sslobj.write(data)错误:[Errno 10054]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆