Ошибка с break при написании цикла в функции
Делаю функцию, которая спрашивает у пользователя, есть ли у него oAuth-токен для Twitch.
import requests
def check_oAuth():
YesOrNo = input("Do you have oAuth code?(Y/N): ")
for j in YesOrNo:
if j == "Yes" or "Y":
break
if YesOrNo == "No" or "N":
client_id = input("Paste your client_id: ")
client_secret = input("Paste your client_secret: ")
# Request an OAuth token
url = 'https://id.twitch.tv/oauth2/token'
data = {
'client_id': client_id,
'client_secret': client_secret,
'grant_type': 'client_credentials'
}
response = requests.post(url, data=data)
# Extract the OAuth token from the response
if response.status_code == 200:
data = response.json()
token = data['access_token']
print("Your oAuth token is: " + token)
В итоге, если при вопросе ответить Yes или Y, то код не прерывается.
Источник: Stack Overflow на русском