Closed CuriousDataLearner closed 10 months ago
Try Base64 encoding the app-id and secret
import base64
app_id = 'your_app_id'
secret = 'your_secret'
# Combine the app_id and secret
combined = f"{app_id}:{secret}"
# Encode the combined string
encoded_credentials = base64.b64encode(combined.encode()).decode()
# Creating the headers
headers = {
"Authorization": f"Bearer {encoded_credentials}",
}
That solved that error. Thank you!
I'm sorry, i got an exception but didn't see the same HTTP Basic: Access denied error is still present.
import requests import jsonpickle import base64
app_id = 'not my app_id' secret = 'not my secret'
combined = f"{app_id}:{secret}"
encoded_credentials = base64.b64encode(combined.encode()).decode()
headers = { "Authorization": f"Bearer {encoded_credentials}", }
data_list = []
url = 'https://api.planningcenteronline.com/people/v2/people'
response = requests.get(url, headers=headers)
if not response.ok: print(response.text) raise Exception("Failed to retrieve data from API")
data = response.json()
OUTPUT IS: raise Exception("Failed to retrieve data from API") Exception: Failed to retrieve data from API
Can you share the error message you get in the response body?
this? PS C:\Users\matth\Python> c:; cd 'c:\Users\matth\Python'; & 'C:\Users\matth\Python\python.exe' 'c:\Users\matth.vscode\extensions\ms-python.python-2023.20.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '62223' '--' 'c:\Users\matth\Python\Planning Center V1-Source.py' HTTP Basic: Access denied.
Traceback (most recent call last):
File "c:\Users\matth\Python\Planning Center V1-Source.py", line 32, in
Oh I think I see the problem... you used "Bearer" instead of "Basic". I think it should be:
headers = {
"Authorization": f"Basic {encoded_credentials}",
}
Thank you! that was it, on with my journey. Y'all are very responsive and helpful. Have a blessed day.
Oh I think I see the problem... you used "Bearer" instead of "Basic". I think it should be:
headers = { "Authorization": f"Basic {encoded_credentials}", }
That was my bad! 🤦♂️
Here is a more succinct solution I found in the Requests documentation.
api_base = 'https://api.planningcenteronline.com'
endpoint = '/people/v2/people'
response = requests.get(
url=api_base + endpoint,
auth=(api_id, secret),
)
No encoding required.
Related Product Which product is this question related to? People
Describe the question I have access to https://people.planningcenteronline.com/ and have read the documentation but can't figure out why i'm getting the access denied error.
What have you tried that worked? Nothing yet
What have you tried that didn't work?
app_id = 'not my app_id' secret = 'not my secret'
headers = { "Authorization": f"Bearer {app_id}:{secret}", } data_list = [] url = 'https://api.planningcenteronline.com/people/v2/people' response = requests.get(url, headers=headers)
if not response.ok: print(response.text) raise Exception("Failed to retrieve data from API")
data = response.json()
Additional context I'm new, but don't give up easy. God bless.
I have..