title: sequence item 0: expected str instance, bytes found
body: <p>This question has been asked before but I am not getting where I went wrong. basically I have one many to many table. and am executing complex query on that so I have written views.pay like this</p>
  
  <pre><code>def flightBooking(request):
      if request.method=='POST':
          form= SearchForm(request.POST)
          if not form.is_valid():
            return render(request, 'booking/search.html',{'form':form})
          else:
                  form.is_valid()
                  data=(form.cleaned_data['fromLocation'],form.cleaned_data['toLocation'])
                  cursor=connection.cursor()
                  cursor.execute("""select flight.name,scheduleDepart.depart_time,scheduleArrive.arrival_time.ai.name from 
                  flight flight,airline ai,flight_schedule scheduleDepart inner join  
                  flight_schedule scheduleArrive on scheduleDepart.flight_id=scheduleArrive.flight_id where scheduleArrive.location_id=%d and scheduleDepart.location_id=%d,
                   and scheduleArrive.flight_id=flight.id and flight.airline_code_id=ai.id """,[data])
                  results=dictFetchAll(cursor)
                  return render(results,'booking/searchResult.html')
                  #return HttpResponse(results,'booking/searchResult.html')
  
  def dictFetchAll(cursor):
      "return all rows with column name"
      columns=[col[0] for col in cursor.description]
      return [
              dict(zip(columns,row))
              for row in cursor.fetchall()
          ]
  </code></pre>
  
  <p>here my from and to location is integer field
  and I got stack trace like this</p>
  
  <pre><code>  File "C:\Program Files (x86)\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
      response = get_response(request)
    File "C:\Program Files (x86)\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
      response = self.process_exception_by_middleware(e, request)
    File "C:\Program Files (x86)\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "E:\kepsla-workspace\WS\demoWS\flightBooking\booking\views.py", line 29, in flightBooking
      and scheduleArrive.flight_id=flight.id and flight.airline_code_id=ai.id """,[data])
    File "C:\Program Files (x86)\lib\site-packages\django\db\backends\utils.py", line 80, in execute
      return super(CursorDebugWrapper, self).execute(sql, params)
    File "C:\Program Files (x86)\lib\site-packages\django\db\backends\utils.py", line 65, in execute
      return self.cursor.execute(sql, params)
    File "C:\Program Files (x86)\lib\site-packages\django\db\backends\mysql\base.py", line 101, in execute
      return self.cursor.execute(query, args)
    File "C:\Program Files (x86)\lib\site-packages\MySQLdb\cursors.py", line 234, in execute
      args = tuple(map(db.literal, args))
    File "C:\Program Files (x86)\lib\site-packages\MySQLdb\connections.py", line 316, in literal
      s = self.escape(o, self.encoders)
    File "C:\Program Files (x86)\lib\site-packages\MySQLdb\converters.py", line 90, in quote_tuple
      return "(%s)" % (','.join(escape_sequence(t, d)))
  TypeError: sequence item 0: expected str instance, bytes found
  [06/Jul/2017 22:45:52] "POST /booking HTTP/1.1" 500 97454
  </code></pre>
  
  <p>so can anyone please tell me where I went wrong? or is there any other way to write this query??</p>