None is None but not working
Daniele Forghieri
guru at digitalfantasy.it
Wed Sep 27 16:53:24 EDT 2017
Il 27/09/2017 22:05, Sayth Renshaw ha scritto:
> 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}
You got None on the member 'RaceDay' of the data, not on all the
data. So you should check for something like:
if data['RaceDay'] is None:
# Missing data
....
else:
# ok, do what you need
...
> 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"])
>
> 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
More information about the Python-list
mailing list