I'm trying to write a code so that if the token exists then it loads the account or else it asks the user for the API token. Below is the code for reference:
from qiskit import IBMQ try: IBMQ.load_account() except Exception as e: api_key = input("Enter IBMQ API Key") IBMQ.save_account(api_key, overwrite=True) IBMQ.load_account()
However, even after using the exception handling, still getting below errors:
RequestsApiError: '401 Client Error: Unauthorized for url: https://auth.quantum-computing.ibm.com/api/users/loginWithToken. Login failed., Error code: 3446.'
IBMQAccountCredentialsInvalidToken: 'Invalid IBM Quantum Experience token found: "" of type <class \'str\'>.'
Any work around this to resolve this issue?