Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to fetch audio files #1190

Open
zerootoad opened this issue Mar 3, 2025 · 3 comments
Open

Not able to fetch audio files #1190

zerootoad opened this issue Mar 3, 2025 · 3 comments

Comments

@zerootoad
Copy link

zerootoad commented Mar 3, 2025

Description

Dont really know if this is my issue, the api issue or cpr itself but im not able to fetch audio files and download them as it gives me a 0 status code which means no response and an empty text, while if i tried downloading it using wget it would actually fetch and download the file.

bool utils::download(const std::string &url, const std::string &path,
                     const std::string &filename) {
  std::string fullPath = path + filename;
  if (std::filesystem::exists(fullPath)) {
    return true;
  } else {
    std::filesystem::create_directories(path);
  }

  auto ses = cpr::Session();
  ses.SetUrl(cpr::Url{url});
  auto ofs = std::ofstream(fullPath);
  auto r = ses.Download(ofs);

  std::cout << r.status_code << std::endl;

  if (r.status_code == 200) {
    std::cout << url << " downloaded\n";
    return true;
  } else {
    std::cout << "Failed to download " << url << std::endl;
    std::cout << r.text << std::endl;
    return false;
  }
}

wget output:

zeroo@arch ~/P/C/R/build> wget https://resources.download.minecraft.net/46/4696189415397c951c0ec1656af648fc06d62330
--2025-03-03 12:33:57--  https://resources.download.minecraft.net/46/4696189415397c951c0ec1656af648fc06d62330
Loaded CA certificate '/etc/ssl/certs/ca-certificates.crt'
Resolving resources.download.minecraft.net (resources.download.minecraft.net)... 13.107.246.60, 2620:1ec:bdf::60
Connecting to resources.download.minecraft.net (resources.download.minecraft.net)|13.107.246.60|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58816 (57K) [application/ogg]
Saving to: ‘4696189415397c951c0ec1656af648fc06d62330.1’

4696189415397 100%  57.44K  --.-KB/s    in 0.03s

2025-03-03 12:33:57 (1.97 MB/s) - ‘4696189415397c951c0ec1656af648fc06d62330.1’ saved [58816/58816]

Example/How to Reproduce

  1. Create a cpr::Session
  2. Set url
  3. create a std::ofstream
  4. Perform the download using session.Download(ofstream)
  5. check the status code and response text

Possible Fix

dont really know man.

Where did you get it from?

GitHub (branch e.g. master)

Additional Context/Your Environment

  • OS: arch linux x86_64
  • Version: Linux 6.12.10-zen1-1-zen
@zerootoad
Copy link
Author

Update
when rerun it works?

@COM8
Copy link
Member

COM8 commented Mar 7, 2025

@zerootoad thanks for reporting. Could you please check the error object inside the response object?
https://docs.libcpr.org/advanced-usage.html#response-objects

Because inside there you find more detailed error information in case the status_code is 0.

@COM8 COM8 self-assigned this Mar 7, 2025
@zerootoad
Copy link
Author

Sure thing i will when im home

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

No branches or pull requests

2 participants