• <small id='qKHsM'></small><noframes id='qKHsM'>

      <legend id='qKHsM'><style id='qKHsM'><dir id='qKHsM'><q id='qKHsM'></q></dir></style></legend>

      <i id='qKHsM'><tr id='qKHsM'><dt id='qKHsM'><q id='qKHsM'><span id='qKHsM'><b id='qKHsM'><form id='qKHsM'><ins id='qKHsM'></ins><ul id='qKHsM'></ul><sub id='qKHsM'></sub></form><legend id='qKHsM'></legend><bdo id='qKHsM'><pre id='qKHsM'><center id='qKHsM'></center></pre></bdo></b><th id='qKHsM'></th></span></q></dt></tr></i><div id='qKHsM'><tfoot id='qKHsM'></tfoot><dl id='qKHsM'><fieldset id='qKHsM'></fieldset></dl></div>
        • <bdo id='qKHsM'></bdo><ul id='qKHsM'></ul>
        <tfoot id='qKHsM'></tfoot>
      1. TypeError:需要一个类似字节的对象,而不是“str"

        TypeError: a bytes-like object is required, not #39;str#39;(TypeError:需要一个类似字节的对象,而不是“str)

              <tfoot id='jJtn5'></tfoot>

                <i id='jJtn5'><tr id='jJtn5'><dt id='jJtn5'><q id='jJtn5'><span id='jJtn5'><b id='jJtn5'><form id='jJtn5'><ins id='jJtn5'></ins><ul id='jJtn5'></ul><sub id='jJtn5'></sub></form><legend id='jJtn5'></legend><bdo id='jJtn5'><pre id='jJtn5'><center id='jJtn5'></center></pre></bdo></b><th id='jJtn5'></th></span></q></dt></tr></i><div id='jJtn5'><tfoot id='jJtn5'></tfoot><dl id='jJtn5'><fieldset id='jJtn5'></fieldset></dl></div>
                  <tbody id='jJtn5'></tbody>
                <legend id='jJtn5'><style id='jJtn5'><dir id='jJtn5'><q id='jJtn5'></q></dir></style></legend>

                <small id='jJtn5'></small><noframes id='jJtn5'>

                  <bdo id='jJtn5'></bdo><ul id='jJtn5'></ul>

                • 本文介绍了TypeError:需要一个类似字节的对象,而不是“str"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  The following is the code that tries to modify the input supplied by a user by using sockets:

                  from socket import *
                  
                  serverName = '127.0.0.1'
                  serverPort = 12000
                  clientSocket = socket(AF_INET, SOCK_DGRAM)
                  message = input('Input lowercase sentence:')
                  clientSocket.sendto(message,(serverName, serverPort))
                  modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
                  print (modifiedMessage)
                  clientSocket.close()
                  

                  When I execute it and supply input the following error occurs:

                  Input lowercase sentence:fdsgfdf
                  Traceback (most recent call last):
                    File "C:srinath filesNETWORKSUDPclient.py", line 6, in <module>
                      clientSocket.sendto(message,(serverName, serverPort))
                  TypeError: a bytes-like object is required, not 'str'
                  

                  What can I do to solve this?

                  解决方案

                  This code is good for Python 2. But in Python 3, results in bit encoding error. I was trying to make a simple TCP server and encountered the same problem. Encoding solves this. Try this with sendto command.

                  clientSocket.sendto(message.encode(),(serverName, serverPort))
                  

                  Similarly you should use .decode() to receive the data on the UDP server side, if you want to print it exactly as it was sent.

                  这篇关于TypeError:需要一个类似字节的对象,而不是“str"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                  How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                  What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                  How to break out of multiple loops?(如何打破多个循环?)
                  How to put the legend out of the plot(如何将传说从情节中剔除)
                  Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)

                    <tfoot id='WVDCJ'></tfoot>
                    • <small id='WVDCJ'></small><noframes id='WVDCJ'>

                      <legend id='WVDCJ'><style id='WVDCJ'><dir id='WVDCJ'><q id='WVDCJ'></q></dir></style></legend>
                      • <bdo id='WVDCJ'></bdo><ul id='WVDCJ'></ul>

                          <i id='WVDCJ'><tr id='WVDCJ'><dt id='WVDCJ'><q id='WVDCJ'><span id='WVDCJ'><b id='WVDCJ'><form id='WVDCJ'><ins id='WVDCJ'></ins><ul id='WVDCJ'></ul><sub id='WVDCJ'></sub></form><legend id='WVDCJ'></legend><bdo id='WVDCJ'><pre id='WVDCJ'><center id='WVDCJ'></center></pre></bdo></b><th id='WVDCJ'></th></span></q></dt></tr></i><div id='WVDCJ'><tfoot id='WVDCJ'></tfoot><dl id='WVDCJ'><fieldset id='WVDCJ'></fieldset></dl></div>
                              <tbody id='WVDCJ'></tbody>