{"id":"066eaa5b838e1bde","repo":"curl/curl","slug":"curl-perform-failed-s","errorCode":null,"errorMessage":"curl perform failed: %s\n","messagePattern":"curl perform failed: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"docs/examples/cookie_interface.c","lineNumber":92,"sourceCode":"int main(void)\n{\n  CURL *curl;\n  CURLcode result;\n\n  result = curl_global_init(CURL_GLOBAL_ALL);\n  if(result != CURLE_OK)\n    return (int)result;\n\n  curl = curl_easy_init();\n  if(curl) {\n    char nline[512];\n\n    curl_easy_setopt(curl, CURLOPT_URL, \"https://www.example.com/\");\n    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\n    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, \"\"); /* start cookie engine */\n    result = curl_easy_perform(curl);\n    if(result != CURLE_OK) {\n      fprintf(stderr, \"curl perform failed: %s\\n\", curl_easy_strerror(result));\n      return 1;\n    }\n\n    print_cookies(curl);\n\n    printf(\"Erasing curl's knowledge of cookies!\\n\");\n    curl_easy_setopt(curl, CURLOPT_COOKIELIST, \"ALL\");\n\n    print_cookies(curl);\n\n    printf(\"-----------------------------------------------\\n\"\n           \"Setting a cookie \\\"PREF\\\" via cookie interface:\\n\");\n    /* Netscape format cookie */\n    snprintf(nline, sizeof(nline), \"%s\\t%s\\t%s\\t%s\\t%.0f\\t%s\\t%s\",\n             \".example.com\", \"TRUE\", \"/\", \"FALSE\",\n             difftime(time(NULL) + 31337, (time_t)0),\n             \"PREF\", \"hello example, I like you!\");\n    result = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/curl/curl/blob/527573490eb2564b3d7c9dd51d8bff963b5d6303/docs/examples/cookie_interface.c#L74-L110","documentation":"Transfer error on the first request in the cookie-interface example: curl_easy_perform() to https://www.example.com/ (with CURLOPT_VERBOSE on and the cookie engine started via CURLOPT_COOKIEFILE \"\") returned non-CURLE_OK. The message prints the translated CURLcode. An identical guard exists at line 135 for the second perform.","triggerScenarios":"curl_easy_perform(curl) at cookie_interface.c:90 fails because of a DNS/TLS/connect problem reaching www.example.com, a TLS backend issue, or proxy misconfiguration. Because CURLOPT_VERBOSE is 1L, detailed diagnostics are printed to stderr just before this message.","commonSituations":"Running offline or with no network egress; a corporate proxy not configured (CURLE_COULDNT_CONNECT); an outdated CA bundle causing CURLE_PEER_FAILED_VERIFICATION; a sandboxed environment blocking outbound HTTPS.","solutions":["Read the verbose output printed just above the message to find the failing stage (DNS, TLS, connect).","If behind a proxy, set CURLOPT_PROXY (and CURLOPT_PROXYPORT/CURLOPT_PROXYTYPE as needed).","For TLS verification errors, update the CA bundle via CURLOPT_CAINFO or point to the system bundle.","Confirm reachability independently with `curl -v https://www.example.com/` from the same host."],"exampleFix":"// before\ncurl_easy_setopt(curl, CURLOPT_URL, \"https://www.example.com/\");\ncurl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\ncurl_easy_setopt(curl, CURLOPT_COOKIEFILE, \"\");\nresult = curl_easy_perform(curl);\nif(result != CURLE_OK)\n  fprintf(stderr, \"curl perform failed: %s\\n\", curl_easy_strerror(result));\n\n// after (harden TLS + optional proxy so the first perform succeeds)\ncurl_easy_setopt(curl, CURLOPT_URL, \"https://www.example.com/\");\ncurl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);\ncurl_easy_setopt(curl, CURLOPT_COOKIEFILE, \"\");\ncurl_easy_setopt(curl, CURLOPT_CAINFO, \"/etc/ssl/certs/ca-bundle.crt\");\ncurl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);\nif(getenv(\"HTTPS_PROXY\"))\n  curl_easy_setopt(curl, CURLOPT_PROXY, getenv(\"HTTPS_PROXY\"));\nresult = curl_easy_perform(curl);\nif(result != CURLE_OK)\n  fprintf(stderr, \"curl perform failed: %s\\n\", curl_easy_strerror(result));","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"int a;\nfor(a = 0; a < 3; ++a) {\n    result = curl_easy_perform(curl);\n    if(result == CURLE_OK) break;\n    if(result != CURLE_COULDNT_CONNECT &&\n       result != CURLE_OPERATION_TIMEDOUT &&\n       result != CURLE_SSL_CONNECT_ERROR) {\n        fprintf(stderr, \"curl perform failed: %s\\n\", curl_easy_strerror(result));\n        break;   /* non-transient: stop retrying */\n    }\n    usleep(200000 << a);   /* 200ms, 400ms, 800ms backoff */\n}","preventionTips":["Enable the cookie engine with a writable CURLOPT_COOKIEFILE so session state survives retries.","Retry only idempotent GETs — the cookie-import flows in this example are safe to retry.","Set CURLOPT_CONNECTTIMEOUT so a dead host fails fast and the retry loop is not stuck.","After exhausting retries, call curl_easy_cleanup to release cookies and pooled connections."],"tags":["libcurl","network","https","cookies","tls"],"analyzedSha":"527573490eb2564b3d7c9dd51d8bff963b5d6303","analyzedAt":"2026-08-01T21:00:26.351Z","schemaVersion":2}