How to download file from woocommerce Shop using API

Viewed 18

I have this project that I'm working on. I am trying to use a shop base on woocommerce. Some of the products in the shop have downloadable attachments.

I tried to access the Link to these downloadable attackments from the woocommerce Database.

def get_download_link(Product_name):
    products = get_allproducts(wcapi)
    for product in products:
        if product['name'] == Product_name:
            return product['downloads'][0]['file']

And it worked. But when I try to actually download the file using:

def download_file(URL):
    response = requests.get(URL)
    open("file.txt", "wb").write(response.content)

I get an 403 Forbidden error code. Now I now that the download operation is seperate from the authentication process issued by the "wcapi".

How can I authenticate myself to be able to use the download link and get the file that I need

0 Answers
Related