Spotipy - set CLIENT_ID and CLIENT_SECRET

巧了我就是萌 提交于 2019-12-08 10:05:19

问题


Where do I go to set CLIENT_ID and CLIENT_SECRET so it's not stored in my python script? The Spotipy documentation says the following, but I can't figure out where I need to go to input these environment variables. Where do I set os.getenv?

    if not client_id:
        client_id = os.getenv('SPOTIPY_CLIENT_ID')

    if not client_secret:
        client_secret = os.getenv('SPOTIPY_CLIENT_SECRET')

    if not client_id:
        raise SpotifyOauthError('No client id')

    if not client_secret:
        raise SpotifyOauthError('No client secret')

回答1:


That depends on what environment you're running in. Environmental variables are variables provided by the operating system, sitting outside the process you're calling them from. If you're in Linux, you would run something like:

export SPOTIFY_CLIENT_ID=yourspotifyclientid
export SPOTIFY_CLIENT_SECRET=yourspotifyclientsecret

You can get more info on environmental variables on Wikipedia.




回答2:


On windows you can set your enviroment variables openning your cmd, change your directory to where your .py file is saved using cd C:\example\example then use SET SPOTIPY_CLIENT_ID=clientIDhere and SET SPOTIPY_CLIENT_SECRET=secretHere to set your variables.




回答3:


For windows 10 powershell terminal, use $env: and put your string code in quotes, worked for me.

$env:SPOTIFY_CLIENT_ID="XXXX"


来源:https://stackoverflow.com/questions/41773685/spotipy-set-client-id-and-client-secret

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!