Q:

Python Datetime Show the Nonetype

I use pymysql to connect mysql
from datetime import datetime
from datetime import timedelta
import pymysql
conn = pymysql.connect()#I simplified the connecting details

print("date:  {}".format(db.fetchone()[0]))
print("the type of the date: {}".format(type(db.fetchone()[0])))
print("one row : {}".format(db.fetchone()))
print("one row of the type: {}".format(type(db.fetchone())))
print("the recent time:　{}".format(datetime.now()))
print("the recent time of the type:　{}".format(type(datetime.now())))

date:  2017-06-01 10:00:00
the type of the date:  one row :
(datetime.datetime(2017, 5, 31, 17, 0), None, 31.5, 88.7, None) 
one row of the type:  
the recent time:　2017-06-01 18:31:04.097299
the recent time of the type:　

But 
while ((time - conn.cursor().fetchone()[0] != timedelta(minutes=15))):
    pass
while ((time - datetime.now() != timedelta(minutes=15))):
    pass

The former showed up:

TypeError: 'NoneType' object is not subscriptable

Why are't they the same type???
Update
MY table:
create table weather ( 
                time timestamp default current_timestamp on update current_timestamp,
                id smallint,
                tpr float(3,1),
                wet float(3,1),
                uv tinyint(2),
                foreign key (id) references chatbot.station(pk));

A:

It seems like db.fetchone() returned None instead of a datetime object.
Is it possible your loop reached the end of your table?

A:

Problem
When we use fetchone method and no records left to read it returns None which is not subscriptable.
Example
Assuming that we want to process non-null time values for all records using query
SELECT time FROM weather WHERE time IS NOT NULL

and time object is current datetime
time = datetime.now()

then we can write it using EAFP coding style like
# or any other `datetime` object
time = datetime.now()
with conn.cursor() as cursor:
    query = "SELECT time FROM weather WHERE time IS NOT NULL"
    cursor.execute(query)
    record = cursor.fetchone()
    try:
        recorded_time = record[0]
    except TypeError:
        # no records found in table for given query,
        # reporting
        print('No records found for query: "{query}"'
              .format(query=query))
    else:
        while time - recorded_time != timedelta(minutes=15):
            record = cursor.fetchone()
            try:
                recorded_time = record[0]
            except TypeError:
                # no more records found, leaving loop
                break

or with checking records for None'ness
# or any other `datetime` object
time = datetime.now()
with conn.cursor() as cursor:
    query = "SELECT time FROM weather WHERE time IS NOT NULL"
    cursor.execute(query)
    record = cursor.fetchone()
    if record is not None:
        recorded_time = record[0]
        while time - recorded_time != timedelta(minutes=15):
            record = cursor.fetchone()
            if record is None:
                # no record found, leaving loop
                break
            recorded_time = record[0]
    else:
        # no records found in table for given query,
        # reporting
        print('No records found for query: "{query}"'
              .format(query=query))

WARNING
Without adding time IS NOT NULL filtration we theoretically can get record with recorded_time equal to None, then difference
time - recorded_time

will raise TypeError since we cannot subtract None from datetime object.

