# How to use 'auth' parameter in GET

**URL:** <https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977>\
**Category:** RequestsLibrary\
**Created:** [24 November 2022 02:16 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977 "2022-11-24T02:16:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanta](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ryanta](https://forum.robotframework.org/u/ryanta)\
**Post date:** [24 November 2022 02:16 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/1 "2022-11-24T02:16:37Z")

</div>

Hi, newbie here. I have these two test cases:

> \*\* Settings \*\*\*  
> Library RequestsLibrary
> 
> \*\*\* Test Cases \*\*\*  
> Without auth  
> GET [https://someURL/mytestfile.txt](https://someURL/mytestfile.txt)
> 
> With auth  
> @{auth} = Create List myuser mypasswd  
> GET [https://someURL/mytestfile.txt](https://someURL/mytestfile.txt) auth=@{auth}

The “Without auth” test passed, but the “With auth” test failed:

With auth | FAIL |  
TypeError: ‘list’ object is not callable

What am I doing wrong?! Thank you in advance.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [24 November 2022 15:59 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/2 "2022-11-24T15:59:44Z")

</div>

Hi @ryanta,

Without seeing the test website no one will be able to answer your question because websites can use a variety of authentication schemes and there is no way for us to know which one.

- The simplest authentication scheme is BASIC auth, for this usually you can just put the username and password in the url:  
`https://<username>:<password>@someURL/mytestfile.txt`
- Mid range authentication schemes can involve setting cookies, headers, or post body data to a auth page and redirect back.
- More complex authentication schemes do things like base64 encoded tokens in the headers or cookies

Hope that helps,

Dave.

---

<div class="post-metadata">

**Author:** ![ryanta](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ryanta](https://forum.robotframework.org/u/ryanta)\
**Post date:** [24 November 2022 16:27 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/3 "2022-11-24T16:27:11Z")

</div>

After much playing around, I found that “GET”, “POST”, “PUT” expect a Tuple in the ‘auth’ parameter, so ‘Create List’ won’t work for ‘auth’.

Instead, I need to use Evaluate to create a Tuple:

```
***Test Cases***
With auth
    ${auth} = Evaluate ("myuser", "mypasswd")
    GET https://someURL/mytestfile.txt auth=${auth}

```

The above works, at least it passes the syntax checking locally and does not throw the _TypeError: ‘list’ object is not callable_ error.

Now, why is there no built-in keyword to create a tuple? There is ‘Create List’ but no ‘Create Tuple’ !

---

<div class="post-metadata">

**Author:** ![robinmackaij](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/robinmackaij/32/126_2.png) [@robinmackaij](https://forum.robotframework.org/u/robinmackaij)\
**Post date:** [27 November 2022 19:43 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/4 "2022-11-27T19:43:00Z")

</div>

In your first example, you have `auth=@{auth}` and in your second (working) example you have `auth=${auth}` (which is the expected use).

List and tuple should both work for basic auth and note that both list and tuple are not callable.

Note that `Create List` creates a list (obviously), so you can just use regular variable assignment:

```python
${auth}= Create List myuser mypasswd
GET https://someURL/mytestfile.txt auth=${auth}

```

---

<div class="post-metadata">

**Author:** ![ryanta](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ryanta](https://forum.robotframework.org/u/ryanta)\
**Post date:** [28 November 2022 14:07 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/5 "2022-11-28T14:07:38Z")

</div>

This simply does not work, please try it yourself:

```
    ${auth}= Create List myuser mypasswd
    GET https://google.com/ auth=${auth}

```

TypeError: ‘list’ object is not callable \<\<\< note that this is a local error, no request sent out of my box.

I’m using Robot Framework 5.0.1 (Python 3.8.10 on linux).

Thank you.

---

<div class="post-metadata">

**Author:** ![robinmackaij](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/robinmackaij/32/126_2.png) [@robinmackaij](https://forum.robotframework.org/u/robinmackaij)\
**Post date:** [28 November 2022 16:01 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/6 "2022-11-28T16:01:27Z")

</div>

You’re right, in the requests library creation of a `HTTPBasicAuth` object is restricted to a 2-length tuple only…that’s a bit inconsistent, since e.g. `files` is documented to take `file tuples` that can in fact be lists.

Now looking at the documentation for RequestsLibrary, a list is supported for basic auth when creating a Session, but only a tuple is supported for auth on non-session operations.

So this is how RequestsLibrary `Create Session` auth is handled:  
`auth = requests.auth.HTTPBasicAuth(*auth) if auth else None`  
So any iterable with length 2 will work with it…but it’ll try to convert an instance of another supported `Auth` object to a `HTTPBasicAuth` instance…which makes it hard to use other authentication types with the RequestsLibrary Sessions.

I guess you could raise an issue about this / provide a PR with an improvement.

---

<div class="post-metadata">

**Author:** ![ryanta](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ryanta](https://forum.robotframework.org/u/ryanta)\
**Post date:** [28 November 2022 21:05 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/7 "2022-11-28T21:05:35Z")

</div>

Would be happy to create an issue for this. Is this the right place to create the issue [Sign in to GitHub · GitHub](https://github.com/robotframework/robotframework/issues/new) ? Also, what is “PR” ?

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [28 November 2022 22:05 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/8 "2022-11-28T22:05:52Z")

</div>

PR = Pull Request :))

---

<div class="post-metadata">

**Author:** ![ryanta](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@ryanta](https://forum.robotframework.org/u/ryanta)\
**Post date:** [29 November 2022 02:00 UTC](https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/9 "2022-11-29T02:00:23Z")

</div>

> <https://github.com/robotframework/robotframework/issues/4550>
>
> This should work but does not:
> \`\`\`
> ${auth}= Create List myuser myp…asswd
> GET https://google.com/ auth=${auth}
> \`\`\`
> The error is:
> \>TypeError: ‘list’ object is not callable 
> 
> Note that this is a local error, no request was sent out of the box.
> 
> I’m using Robot Framework 5.0.1 (Python 3.8.10 on linux).
> 
> The root cause was discussed in this Robot Framework forum thread https://forum.robotframework.org/t/how-to-use-auth-parameter-in-get/4977/6, repeated here with minor editing.
> 
> In the Requests library, the creation of a \`HTTPBasicAuth\` object is restricted to a 2-length tuple only. That’s a bit inconsistent since e.g. \`files\` is documented to take file-tuples that can in fact be lists.
> 
> Now looking at the documentation for RequestsLibrary, a list is supported for basic auth when creating a Session, but only a tuple is supported for auth on non-session operations.
> 
> So this is how RequestsLibrary \`Create Session\` auth is handled:
> \`auth = requests.auth.HTTPBasicAuth(\*auth) if auth else None\`
> 
> So any iterable with length 2 will work with it… but it’ll try to convert an instance of another supported Auth object to a HTTPBasicAuth instance… which makes it hard to use other authentication types with the RequestsLibrary Sessions.
> \[End of Quote\]
> 
> The not so nice workaround is to directly create a tuple then pass it to GET:
> \`\`\`
> With auth
> ${auth} = Evaluate ("myuser", "mypasswd")
> GET https://someURL/mytestfile.txt auth=${auth}
> \`\`\`
