'Inputing auth code for youtube api on a script that is running in the background gives error

When I try to type in the authorization code for youtube api on a script that is ran in the background, I get an error.

Code to get credentials:

import googleapiclient.discovery
from google_auth_oauthlib.flow import InstalledAppFlow

flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build("youtube", "v3", credentials = credentials)

This is what happens when I try to run it in the background:

$ python3 script.py &

Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=984089725210-vkpmcsi5h4uu7omicp8m8bdcegsqrhvs.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.force-ssl&state=JKvRxEoFiLXUcRSJC73GyzbvO4qBVb&prompt=consent&access_type=offline

Enter the authorization code: 4/1AX4XfWgvJ2hu9_sgU7eqXk_pr5soCyOkHDt-2_chvunZvWyATCtkb4e5yfk

bash: 4/1AX4XfWgvJ2hu9_sgU7eqXk_pr5soCyOkHDt-2_chvunZvWyATCtkb4e5yfk: No such file or directory

This does not happen when I run the script normally.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source