libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.54k stars 930 forks source link

Error code 4 and empty error message #791

Closed JimmyRice closed 2 years ago

JimmyRice commented 2 years ago

Description

I'm working on a simple console application, and an internal error has occurred when I'm requesting an API.

Code

string steamId;

cout << "Provide a Steam ID: ";
cin >> steamId;

cout << "Working on it...";
cout << endl << endl;

const string path = "https://public-api.tracker.gg/v2/csgo/standard/profile/steam/" + steamId;

cpr::Url url = cpr::Url{path};
cpr::Header header = cpr::Header{{"TRN-Api-Key", api_config::get_token()}};
cpr::Response response = cpr::Get(url, header);

cout << response.status_code << endl;
cout << static_cast<int>(response.error.code) << endl;
cerr << response.error.message << endl

Expected Behavior

Expect the request from the API server to be received correctly and output via response.text

Actual Behavior

response.status_code is 0 response.error.code is 4 response.error.message is empty

Context

I can't get a response from the API server

Your Environment

OS: macOS 12.4 (MacBook Pro, Intel version, 2020) curl: 7.80.0 CMake: 3.22.3 (with CLion)

-- Enabled curl SSL
-- curl version=[7.80.0]
-- Could NOT find LibSSH2 (missing: LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR) 
-- CA path only supported by OpenSSL, GnuTLS or mbed TLS. Set CURL_CA_PATH=none or enable one of those TLS backends.
-- Enabled features: SSL IPv6 unixsockets libz AsynchDNS Largefile alt-svc HSTS
-- Enabled protocols: HTTP HTTPS
-- Enabled SSL backends: Secure Transport
-- Configuring done
-- Generating done
COM8 commented 2 years ago

Thanks for reporting! Error code 4 stands for an internal error inside curl. Could you please provide a minimal example project with all your CMake stuff, so I can reproduce it?

Based on the following line I think something is wrong with the TLS configuration.

-- CA path only supported by OpenSSL, GnuTLS or mbed TLS. Set CURL_CA_PATH=none or enable one of those TLS backends.

And could you please paste the complete log from your CMake configure phase (cmake ..)?

JimmyRice commented 2 years ago

Hi! Thank you so much for taking the time to respond to me!

I have good news on my side, when I created a new sample project and tested it, I found it worked, so I reopened my simple console application and found that the requests were working. So there seem to be no more problems at the moment.

Thank you so much.