How to decipher error "Nonetype" Error

kbtyo ahlusar.ahluwalia at gmail.com
Wed Sep 2 18:50:20 EDT 2015


On Wednesday, September 2, 2015 at 6:29:05 PM UTC-4, Chris Angelico wrote:
> On Thu, Sep 3, 2015 at 8:15 AM, kbtyo wrote:
> > However, when I hit line 40 (referencing the gist), I receive the following error:
> >
> > ---------------------------------------------------------------------------
> > TypeError                                 Traceback (most recent call last)
> > <ipython-input-56-4eff0a608e19> in <module>()
> >      23         # to ensure that the field names in the XML don't match (and override) the
> >      24         # field names already in the dictionary
> > ---> 25         row.update(xml_data)
> >      26         # ensure that the headers have all the right fields
> >      27         headers.update(row.keys())
> >
> > TypeError: 'NoneType' object is not iterable
> >
> > I can only infer I am passing or converting an empty key or empty row. I welcome feedback.
> 
> NoneType is the type of the singleton object None. So what this means
> is that xml_data is None at this point.
> 
> In your just_xml_data() function, which is what provides xml_data at
> that point, there are two code branches that matter here: one is the
> "else: return xml", and the other is the implicit "return None" at the
> end of the function. If you catch an exception, you print out a
> message and then allow the function to return None. Is that really
> your intention? It seems an odd way to do things, but if that is what
> you want, you'll need to cope with the None return in the main
> routine.
> 
> BTW, your gist has a couple of non-comments on lines 48 and 49. If you
> can make sure that your code is functionally correct, it'll be easier
> for us to test. (Even more so if you can include a sample input file
> in the gist, though preferably not a huge one.) At the moment, I'm
> just eyeballing the code itself, but if someone can actually run the
> script and reproduce the exact error you're seeing, it makes debugging
> that much easier.
> 
> All the best!
> 
> ChrisA

Hi Chris:

I made changes to the gist: https://gist.github.com/ahlusar1989/de2381c1fb77e96ae601

Ahhhhhh!!!!  Thanks for catching that. No, I want to skip over the Exception and return the xml_data in the try block. I didn't realize that was the behaviour. I don't want to break the iterative loop. Any advice on how to absolve this?

Thanks.



More information about the Python-list mailing list