title: Python MySQL connector - unread result found when using fetchone
body: <p>I am inserting JSON data into a MySQL database</p>
  
  <p>I am parsing the JSON and then inserting it into a MySQL db using the python connector</p>
  
  <p>Through trial, I can see the error is associated with this piece of code</p>
  
  <pre><code>for steps in result['routes'][0]['legs'][0]['steps']:
      query = ('SELECT leg_no FROM leg_data WHERE travel_mode = %s AND Orig_lat = %s AND Orig_lng = %s AND Dest_lat = %s AND Dest_lng = %s AND time_stamp = %s')
      if steps['travel_mode'] == "pub_tran":
          travel_mode = steps['travel_mode']
          Orig_lat = steps['var_1']['dep']['lat']
          Orig_lng = steps['var_1']['dep']['lng']
          Dest_lat = steps['var_1']['arr']['lat']
          Dest_lng = steps['var_1']['arr']['lng']
          time_stamp = leg['_sent_time_stamp'] 
      if steps['travel_mode'] =="a_pied":
          query = ('SELECT leg_no FROM leg_data WHERE travel_mode = %s AND Orig_lat = %s AND Orig_lng = %s AND Dest_lat = %s AND Dest_lng = %s AND time_stamp = %s')
          travel_mode = steps['travel_mode']
          Orig_lat = steps['var_2']['lat']
          Orig_lng = steps['var_2']['lng']
          Dest_lat = steps['var_2']['lat']
          Dest_lng = steps['var_2']['lng']
          time_stamp = leg['_sent_time_stamp']
      cursor.execute(query,(travel_mode, Orig_lat, Orig_lng, Dest_lat, Dest_lng, time_stamp))
      leg_no = cursor.fetchone()[0]
      print(leg_no)
  </code></pre>
  
  <p>I have inserted higher level details and am now searching the database to associate this lower level information with its parent. The only way to find this unique value is to search via the origin and destination coordinates with the time_stamp. I believe the logic is sound and by printing the leg_no immediately after this section, I can see values which appear at first inspection to be correct</p>
  
  <p>However, when added to the rest of the code, it causes subsequent sections where more data is inserted using the cursor to fail with this error - </p>
  
  <pre><code>    raise errors.InternalError("Unread result found.")
  mysql.connector.errors.InternalError: Unread result found.
  </code></pre>
  
  <p>The issue seems similar to <a href="https://stackoverflow.com/questions/15336767/mysql-unread-result-with-python">MySQL Unread Result with Python</a></p>
  
  <p>Is the query too complex and needs splitting or is there another issue?</p>
  
  <p>If the query is indeed too complex, can anyone advise how best to split this? </p>
  
  <p>EDIT As per @Gord's help, Ive tried to dump any unread results</p>
  
  <pre><code>cursor.execute(query,(leg_travel_mode, leg_Orig_lat, leg_Orig_lng, leg_Dest_lat, leg_Dest_lng))
              leg_no = cursor.fetchone()[0]
              try:
                  cursor.fetchall()
              except mysql.connector.errors.InterfaceError as ie:
                  if ie.msg == 'No result set to fetch from.':
                      pass
                  else:
                      raise
              cursor.execute(query,(leg_travel_mode, leg_Orig_lat, leg_Orig_lng, leg_Dest_lat, leg_Dest_lng, time_stamp))
  </code></pre>
  
  <p>But, I still get </p>
  
  <pre><code>raise errors.InternalError("Unread result found.")
  mysql.connector.errors.InternalError: Unread result found.
  [Finished in 3.3s with exit code 1]
  </code></pre>
  
  <p><em>scratches head</em></p>
  
  <p>EDIT 2 - when I print the ie.msg, I get - </p>
  
  <pre><code>No result set to fetch from
  </code></pre>