# Error related to gnuTLS library

**URL:** <https://forum.legato.io/t/error-related-to-gnutls-library/2397>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [March 27, 2017, 7:59am UTC](https://forum.legato.io/t/error-related-to-gnutls-library/2397 "2017-03-27T07:59:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 27, 2017, 7:59am UTC](https://forum.legato.io/t/error-related-to-gnutls-library/2397/1 "2017-03-27T07:59:00Z")

</div>

Hello everyone,

I am using curl methods in my project.  
But before my code execution starts, there is error related to gnuTLS library  
**Error in GnuTLS initialization: Failed to acquire random data.**

and while executing code, there is error while curl\_easy\_perform()  
**curl\_easy\_perform() failed: Couldn’t resolve host name**

code flow:  
CURL \*curl;  
CURLcode res;

```
    LE_INFO("INTO:::gET uRL METHOD ");

    res = curl_global_init(CURL_GLOBAL_NOTHING);

    if(res == CURLE_OK)
    {

    curl = curl_easy_init();
    if (curl)
    {
       res = curl_easy_setopt(curl, CURLOPT_URL,Url); //https://93.184.216.34
        if (res != CURLE_OK)
                {
                    LE_ERROR("curl_easy_setopt failed: %s", curl_easy_strerror(res));
                    if (res == CURLE_SSL_CACERT)
                    {
                        LE_ERROR(SSL_ERROR_HELP);
                        LE_ERROR(SSL_ERROR_HELP_2);
                    }
                }

        LE_INFO("INTO = Performed setopt_url ");

        res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, PrintCallback);
        if (res != CURLE_OK)
                        {
                            LE_ERROR("curl_easy_setopt failed: %s", curl_easy_strerror(res));
                            if (res == CURLE_SSL_CACERT)
                            {
                                LE_ERROR(SSL_ERROR_HELP);
                                LE_ERROR(SSL_ERROR_HELP_2);
                            }
                        }

        LE_INFO("INTO = Performed setopt_writefunction ");

        res = curl_easy_perform(curl);
        if (res != CURLE_OK)
        {
            LE_ERROR("curl_easy_perform() failed: %s", curl_easy_strerror(res));
            if (res == CURLE_SSL_CACERT)
            {
                LE_ERROR(SSL_ERROR_HELP);
                LE_ERROR(SSL_ERROR_HELP_2);
            }
        }

        LE_INFO("INTO = Performed curl_easy_perform and now cleaning ");

        curl_easy_cleanup(curl);

```

component.cdef file :  
\> sources:

> ```
> {
> CurlBasedProjectComponent.cpp
> }
> requires:
> {
> api:
> {
> le_data.api [manual-start]    
> }
> file: 
> {
> /usr/lib/libcurl.so.5 /lib/
> /usr/lib/libgmp.so.10 /lib/
> /usr/lib/libgnutls.so.28 /lib/
> /usr/lib/libhogweed.so.2 /lib/
> /usr/lib/libnettle.so.4 /lib/
> /lib/libz.so.1 /lib/
> }
> }
> 
> ```

Kindly give solution for both errors

---

<div class="post-metadata">

**Author:** ![Vasantha\_lax](https://avatars.discourse-cdn.com/v4/letter/v/5f9b8f/32.png) [@Vasantha\_lax](https://forum.legato.io/u/Vasantha_lax)\
**Post date:** [December 16, 2017, 10:29am UTC](https://forum.legato.io/t/error-related-to-gnutls-library/2397/2 "2017-12-16T10:29:04Z")

</div>

There is a sample application available in legato which will you give you a working example to use curl.  
[legato-af/apps/sample/httpGet at master · legatoproject/legato-af · GitHub](https://github.com/legatoproject/legato-af/tree/master/apps/sample/httpGet)
