I regret displaying my ignorance of basic Python and HTTP authentication here.
I have the following in a Google Colab cell. I know that both password and API key are not required, but I was experimenting with every combination of both without success.
I get the expected results from the public list, but not from my private list. I bomb out with “Private failed”.
I believe that I’m using the URL corresponding to retrieving a token, but not accepting and passing the token on subsequent calls. For my simple-minded purposes, I’d be happiest with basic HTTP authentication in the headers.
USERNAME = "charlie@hamufamu.org"
PASSWORD = "what I type to log in" # @param {type:"string"}
REMOTE_KEY = "what I see on the profile page" # @param {type:"string"}
import requests
session = requests.Session()
# This "works" even with the wrong credentials
response = session.post(
"https://checkvist.com/auth/login?version=2",
data={"username": USERNAME, "password": PASSWORD, "remote_key": REMOTE_KEY})
if response.status_code != 200:
raise SystemExit("Authentication failed")
# Access a public list
response = session.get("https://checkvist.com/checklists/485490.json")
if response.status_code != 200:
raise SystemExit("Public failed")
print(response.content)
# Get my private list
response = session.get("https://checkvist.com/checklists/464277.json")
if response.status_code != 200:
raise SystemExit("Private failed")
print(response.content)
# We made it to the end
print("Success!")
I’ve resolved my problem. Here’s the approach with basic HTTP authentication:
import requests
from google.colab import userdata
# Replace 'username' and 'password' with your actual credentials
username = userdata.get('username')
password = userdata.get('password')
# Base URL for the Checkvist API
base_url = 'https://checkvist.com/checklists.json'
# Send a GET request to retrieve the list of checklists
response = requests.get(base_url, auth=(username, password))
# Check if the request was successful
if response.status_code == 200:
# Print the list of checklists
checklists = response.json()
for checklist in checklists:
print(checklist['name'])
else:
print(f"Failed to retrieve checklists: {response.status_code} - {response.text}")
Playing around and learning. Finally forced myself to learn basic HTTP authentication in Python, as seen above.
Building myself a little utility to take all my overdue items and to scatter them to random dates in the future. (It may not be quite as silly as it sounds. Or it may be.)
(The original, incorrect, answers I received were also from ChatGPT. But once I learned the right terms to ask for, I coaxed it into the right answer.)
For the benefit of other newbies, basic HTTP authorization needs to be provided on each call. (I assume that sessions solve this problem, but I haven’t gotten there yet.)
import requests
from google.colab import userdata
auth = (userdata.get('username'), userdata.get('password'))
# This works and lists the name of each checklist in my account.
response = requests.get('https://checkvist.com/checklists.json', auth=auth)
if response.status_code != 200:
raise SystemExit(f"Failed to retrieve checklists the first time:"
+ " {response.status_code} - {response.text}")
for checklist in response.json():
print(checklist['name'])
# This will fail because authorization needs to be provided each time.
response = requests.get('https://checkvist.com/checklists.json')
if response.status_code != 200:
raise SystemExit(f"Failed to retrieve checklists the second time:"
+ " {response.status_code} - {response.text}")
for checklist in response.json():
print(checklist['name'])