Can any one help me with python code?

halamadrid7

BANNED
Joined
Jan 19, 2023
Messages
266
Reaction score
117
from BunnyCDN.Storage import Storage
# Initialize BunnyCDN Storage object with your API key and storage zone name
obj_storage = Storage('723fbcb5-1fd5c4eed0137a8bd-abaa-4fddb9faf17d', 'testing-dec')
# Specify the file name (without path)
file_name = 'Image.jpg'
# Specify the storage path (directory) where you want to upload the file
storage_path = 'testing-dec/Images/' + file_name # Specify the directory and file name where you want to upload
# Upload the file
response = obj_storage.PutFile(file_name, storage_path)
# Check the response
if response['status'] == 'success':
print("File uploaded successfully.")
else:
print("Failed to upload file. Error:", response['msg'])

I am getting 401 error. Can any one provide new code or changes to upload and get images from local storage to folder in storage?
 
First. Do you installed the required library’s?
 
Check your access details. 401 http status means the api call is unauthorised (simply put, wrong key).
 
Check your access details. 401 http status means the api call is unauthorised (simply put, wrong key).
Yeah I found that acount API is not storage API to use but still there is something I am missing
 
Last edited:
I need to see what error you receive when you run that code. Can you run it?
 
I need to see what error you receive when you run that code. Can you run it?
Yup, Failed to upload file. Error: Upload Failed HTTP Error Occured: 401 Client Error: Unauthorized for url: https://storage.bunnycdn.com/testing-dec/festing.a-cdn.net/Images/Image.jpg

Updated the code also but same error
from BunnyCDN.Storage import Storage
# Initialize BunnyCDN Storage object with your API key and storage zone name
obj_storage = Storage('723fbcb5-a79a-405b-808b7f7-b29b-4dfd-abaa-4fddb9faf17d', 'testing-dec')
# Specify the file name (without path)
file_name = 'Image.jpg'
# Specify the storage path (directory) where you want to upload the file
storage_path = 'festing.a-cdn.net/Images/' + file_name # Specify the directory and file name where you want to upload
# Upload the file
response = obj_storage.PutFile(file_name, storage_path)
# Check the response
if response['status'] == 'success':
print("File uploaded successfully.")
else:
print("Failed to upload file. Error:", response['msg'])
 
The error you are receiving had already been told above, I had not noticed.

It is a product of the api key, you can generate a new key and use it, maybe that way you can solve it.
 
Yeah I found that acount API is not storage API to use but still there is something I am missing
There may well be other errors. But if I was you, I would try solving one problem at once. When you get 401 in an api call, you always check the key and permissions first.
 
Back
Top