When trying the example, I noticed that the token file, which should be generated according to this line is not being created.
Luckily the download of the data and the authentication process are unaffected.
This behavior is peculiar because when the function is called from a terminal, the file is indeed created.