Nonetype object has no attribute 'id'
Question: I am retrieving the last id from mssql and trying to incrementing it and
storing the fie name with the id.. But I am getting "Attribute error :
Nonetype object has no attribute 'id'"..The code and the error goes here :

    
    
    import Tkinter,tkFileDialog 
    import shutil    
    import pyodbc    
    cnxn = pyodbc.connect("DRIVER={SQL Server};SERVER=PAVAN;DATABASE=video;Trusted_Connection=yes;")   
    cursor = cnxn.cursor()  
    cursor.execute("SELECT TOP 1 id  FROM files ORDER BY id DESC ")
    
    while 1:   
        row = cursor.fetchone()  
        if not row:   
            break   
        print row.id    
    cnxn.close()    
    middle = Tkinter.Tk()
    
    def withdraw():    
       dirname = tkFileDialog.askopenfilename(parent=middle,initialdir="H:/",title='Please 
    select a file')    
       a="H:python(test)\py_"+row.id+".mp4"    
       b=shutil.copyfile(dirname,a)
    
       if b!="":    
           print "Successfully Copied"    
       else:    
           print "Could not be copied"
    
    B = Tkinter.Button(middle, text ="UPLOAD", command = withdraw)    
    middle.geometry("450x300+100+100")    
    middle.configure(background="black")    
    B.pack() 
    middle.mainloop() 
    

The error I'm getting is:

    
    
    Traceback (most recent call last):  
      File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
          return self.func(*args)
      File "C:\Users\hp\Desktop\upload.py", line 20, in withdraw
        a="H:python(test)\py_"+row.id+".mp4"
    AttributeError: 'NoneType' object has no attribute 'id'
    


Answer: This occurs when the you try to get **id** Attribute from object which is of
None type , Here is a case :

    
    
    >> a = None
    >> a.id
    AttributeError: 'NoneType' object has no attribute 'id'
    

So it might be the case object **row** is of None type , and you are trying to
print row.id

You may check for the type of row using :

    
    
    type(**row**)
    

With Regards Deepak

