title: How to fix: TypeError: a bytes-like object is required, not 'str'
body: <p>I have recently started programming.
  I am trying to simulate an ethereum transaction with the help of Ropsten.
  When I try to run the function (sendTransaction (&quot;message&quot;)) with the Django's shell I get this error: TypeError: a bytes-like object is required, not 'str'.
  The full errors track is the following:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;&lt;console&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;C:\Users\Francesco\bakeka\bloggo\utils.py&quot;, line 18, in sendTransaction
      tx = w3.eth.sendTransaction(signedTx.rawTransaction)
    File &quot;C:\Users\Francesco\bakeka\globale\lib\site-packages\web3\eth.py&quot;, line 577, in send_transaction
      return self._send_transaction(transaction)
    File &quot;C:\Users\Francesco\bakeka\globale\lib\site-packages\web3\module.py&quot;, line 53, in caller
      (method_str, params), response_formatters = method.process_params(module, *args, **kwargs)  # noqa: E501
    File &quot;C:\Users\Francesco\bakeka\globale\lib\site-packages\web3\method.py&quot;, line 179, in process_params
      params = self.input_munger(module, args, kwargs)
    File &quot;C:\Users\Francesco\bakeka\globale\lib\site-packages\web3\method.py&quot;, line 168, in input_munger
      root_munger(module, *args, **kwargs),
    File &quot;C:\Users\Francesco\bakeka\globale\lib\site-packages\web3\eth.py&quot;, line 120, in send_transaction_munger
      if 'from' not in transaction and is_checksum_address(self.default_account):
  TypeError: a bytes-like object is required, not 'str'
  </code></pre>
  <p>(Francesco is my username, bakeka is my project, globale is my venv)</p>
  <pre><code>from web3 import Web3
  
  def sendTransaction(message):
      w3 = Web3(Web3.HTTPProvider('My Ropsten Ip'))
      address = 'my addres'
      privateKey = 'my private key'
      nonce = w3.eth.getTransactionCount(address)
      gasPrice = w3.eth.gasPrice
      value = w3.toWei(0, 'ether')
      signedTx = w3.eth.account.signTransaction(dict(
          nonce = nonce,
          gasPrice = gasPrice,
          gas = 10000,
          to = '0x0000000000000000000000000000000000000000',
          value = value,
          data = message.encode('utf-8'),
      ), privateKey)
      tx = w3.eth.sendTransaction(signedTx.rawTransaction)
      txId = w3.toHex(tx)
      return txId
  </code></pre>
  <p>Can you help me? Thank u all!!</p>