Skip to content

Instantly share code, notes, and snippets.

@TheMuellenator
Forked from angelabauer/main.py
Last active June 25, 2025 17:06
Show Gist options
  • Save TheMuellenator/974c39779ec516c4c60e918c001e48ba to your computer and use it in GitHub Desktop.
Save TheMuellenator/974c39779ec516c4c60e918c001e48ba to your computer and use it in GitHub Desktop.
Day 38 Step 5 L335 - Solution
#No Authentication
sheet_response = requests.post(sheet_endpoint, json=sheet_inputs)
#Basic Authentication
sheet_response = requests.post(
sheet_endpoint,
json=sheet_inputs,
auth=(
YOUR USERNAME,
YOUR PASSWORD,
)
)
#Bearer Token Authentication
bearer_headers = {
"Authorization": f"Bearer {YOUR TOKEN}"
}
sheet_response = requests.post(
sheet_endpoint,
json=sheet_inputs,
headers=bearer_headers
)
@JakubHudrlik
Copy link

JakubHudrlik commented Jul 22, 2024

BEARER TOKEN AUTHENTICATION FIX
For me it was probably the bearer token you create at Sheety, I imagine it didn't meet some parameters so I tried copying the token that gets created for you in the Basic authentication from username and password and changed it a little and that worked.
Hope it helps someone

@WilkensonDave
Copy link

It works like that:
basic = HTTPBasicAuth('username', 'pass')

responses = requests.post(url=SHEETY_API, json=my_data, auth=basic)

@Llamalu1
Copy link

So much easier just using the basic authentication. like the comment above just don't forget
from requests.auth import HTTPBasicAuth

@gideondakore
Copy link

gideondakore commented Oct 26, 2024

  1. I was able to fixed the problem after removing the "Bearer" from the Authorization header. i.e

" req_body = {
"workout" : {
"date": date,
"time": current_time,
"exercise": exercise.title(),
"duration": duration,
"calories": calories
}
}

    sheety_header = {
        "Authorization": f"Bearer {bearer_token}"
    }
    sheety_url = "https://api.sheety.co/YOUR_KEY/copyOfMyWorkouts/workouts"

    response = requests.post(url=sheety_url, json=req_body, headers=sheety_header)
    "
    
    
    
    **To This:**
    
    
    
    "req_body = {
        "workout" : {
        "date": date,
        "time": current_time,
        "exercise": exercise.title(),
        "duration": duration,
        "calories": calories
        }
    }

    sheety_header = {
        **"Authorization": f"{bearer_token}"**
    }
    sheety_url = "https://api.sheety.co/YOUR_KEY/copyOfMyWorkouts/workouts"

    response = requests.post(url=sheety_url, json=req_body, headers=sheety_header)"
    
    2. And you can also check your google account under security, and make sure you allow Sheety access to your google sheet.
    
    3. Check your endpoint well

@Ammarmalik98
Copy link

the next wored for me too:
headers_sheety = { "Authorization": MY AUTHORIZATION HEADER, }
sheety_response = requests.post(url=ENDPOINT, json=new_workout_data, headers=headers_sheety) print(sheety_response.text)
image_2021-07-27_022158

yes, that worked for me as well.

Yup, i used this code instead of my password...and i worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment