# GET Request : only return the response code for image

**URL:** <https://forum.robotframework.org/t/get-request-only-return-the-response-code-for-image/2711>\
**Category:** RequestsLibrary\
**Created:** [3 November 2021 14:52 UTC](https://forum.robotframework.org/t/get-request-only-return-the-response-code-for-image/2711 "2021-11-03T14:52:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Centaure13](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Centaure13](https://forum.robotframework.org/u/Centaure13)\
**Post date:** [3 November 2021 14:52 UTC](https://forum.robotframework.org/t/get-request-only-return-the-response-code-for-image/2711/1 "2021-11-03T14:52:04Z")

</div>

Hello,

In order to be sure that my image is not broken, I do a `GET` request like this :

```
    ${temp}= Get Element Attribute //div[@class="photo_bg"]/img src 
    ${background}= GET ${temp} expected_status=200

```

I only want the response code but when I execute my test, the image is “read” and on the console, there are characters like �5�����1 and my log is unreadable.

Have you an idea to only get the response code without reading the image ?

Thanks a lot

John.

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [3 November 2021 17:40 UTC](https://forum.robotframework.org/t/get-request-only-return-the-response-code-for-image/2711/2 "2021-11-03T17:40:01Z")

</div>

I don’t know if there is a keyword for that in RESTLibrary (this is the one you used, right?), but here is my suggestion:

```python
${temp}= Get Element Attribute //div[@class="photo_bg"]/img src
${loglevel}= Set Log Level NONE
${background}= GET ${temp} expected_status=200
Set Log Level ${loglevel}

```

---

<div class="post-metadata">

**Author:** ![Centaure13](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Centaure13](https://forum.robotframework.org/u/Centaure13)\
**Post date:** [4 November 2021 07:23 UTC](https://forum.robotframework.org/t/get-request-only-return-the-response-code-for-image/2711/3 "2021-11-04T07:23:21Z")

</div>

Hello,

Your idea seems to be good but when I try it, indeed the special characters have disappeared but when the test fails (for example I put a 400 expected\_status, I don’t see anymore the error message)

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [4 November 2021 10:35 UTC](https://forum.robotframework.org/t/get-request-only-return-the-response-code-for-image/2711/4 "2021-11-04T10:35:20Z")

</div>

I solved your original problem 🙂

You have to add a different logic for different cases, for example:

```python
    ${temp}= Get Element Attribute //div[@class="photo_bg"]/img src
    ${loglevel}= Set Log Level NONE
    &{res}= GET ${temp}
    IF ${res.status} == ${200}
        Log Image link is OK
    ELSE IF ${res.status} == ${400}
        Output response body
    ELSE
        Log Unexpected response!
        Output response
    END
    Set Log Level ${loglevel}
```

---

<div class="post-metadata">

**Author:** ![JaPyR](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/japyr/32/756_2.png) [@JaPyR](https://forum.robotframework.org/u/JaPyR)\
**Post date:** [8 November 2021 10:22 UTC](https://forum.robotframework.org/t/get-request-only-return-the-response-code-for-image/2711/5 "2021-11-08T10:22:55Z")

</div>

If you are interested in response code only maybe `HEAD` keyword would work for you better?

---

<div class="post-metadata">

**Author:** ![Centaure13](https://avatars.discourse-cdn.com/v4/letter/c/58956e/32.png) [@Centaure13](https://forum.robotframework.org/u/Centaure13)\
**Post date:** [9 November 2021 07:43 UTC](https://forum.robotframework.org/t/get-request-only-return-the-response-code-for-image/2711/6 "2021-11-09T07:43:42Z")

</div>

Hello,

Thanks for all your help.  
Your solution is working ! I have tried the Helio’s one but it failed…

Thanks a lot 🙂

For information, I have wrote :

```
${temp}= Get Element Attribute //div[@class="photo_bg"]/img src 
${background}= HEAD expected_status=200
```
