擅长:python、mysql、java
<p>正如回溯所说,这是一个TypeError:bytes对象是必需的,而不是str</p>
<p>因此,您可以在字符串上使用<code>.encode()</code>来获得一个类似的bytes对象,然后使用<code>.decode()</code>来取回字符串。在</p>
<pre><code>MESSAGE = 'Hello, World!'
encoded = str.encode(MESSAGE) # b'Hello, World!'
decoded = encoded.decode() # 'Hello, World!'
</code></pre>
<p>在这里,这个链接,你可能会发现它很有用。<a href="https://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3">Best way to convert string to bytes in Python 3?
</a></p>
<p>希望有帮助。在</p>