None is None but not working

Gary Herron gherron at digipen.edu
Wed Sep 27 17:09:57 EDT 2017


On 09/27/2017 01:05 PM, Sayth Renshaw wrote:
> Hi
>
> I have got a successful script setup to rotate through dates and download json data from the url.
>
> As the api returns 200 whether successful I want to check if the file returned is not successful.
>
> when a file doesn't exist the api returns
> {'RaceDay': None, 'ErrorInfo': {'SystemId': 200, 'ErrorNo': 55013, 'DisplayMessage': 'File Not Found.', 'ContactSupport': False, 'SupportErrorReference': '200-55013'}, 'Success': False}
>
> When I call data = r.json() it says its type is None if it is not successful so I thought it easier to check that.
>
> However checking for None does not work the flow in my if else falls straight to else.
>
> for dates in fullUrl:
>      r = requests.get(dates)
>      data = r.json()
>      if data is None:
>          print("Nothing here")
>      else:
>          print(data["RaceDay"])

Your data is not None, it's a full dictionary.

However, data["RaceDay"] *is* None as shown in your output.  Thus your 
test should be:
     if data["RaceDay"] is None: ...
rather than
     if data is None: ...




>
> and I get output of
>
> None
> None
> {'MeetingDate': '2017-01- ... and so on.
>
> How can I actually get this to check?
>
> If i use type(data) I also get None.
>
> Cheers
>
> Sayth


-- 
Dr. Gary Herron
Professor of Computer Science
DigiPen Institute of Technology
(425) 895-4418





More information about the Python-list mailing list