How to download from python-eve endpoint that serves files using python requests? I keep getting 401 errors

81 views Asked by At

There's a Python-Eve installation that serves files using endpoints.

The endpoint looks like /smartapi/datafiles/5f4deca38cc01b4384f68529

The Python-Eve installation is not maintained by me.

I can download the file using my credentials successfully using curl.

curl -u username:password   https://thepythoneve.installation/smartapi/datafiles/5f4deca38cc01b4384f68529 --output test.xlsx

However, when I tried to use python requests, I keep getting 401 unauthorized access

          auth = HTTPBasicAuth(settings.username, settings.password)
          with requests.get(url, auth=auth, stream=True) as response:
                response.raise_for_status()
                with open(file_path, "wb") as out_file:
                    for chunk in response.iter_content(chunk_size=1024 * 1024):  # 1MB chunks
                        out_file.write(chunk)
                logger.info("Download finished successfully")
                return (response, file_path)

I will keep failing at the raise_for_status

I hope not to use pycurl. I like to still use requests What am I missing from my code to make this work?

0

There are 0 answers