# get\_url always return 401 Unauthorized

**URL:** <https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765>\
**Category:** Ansible Project\
**Created:** [June 11, 2018, 9:59am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765 "2018-06-11T09:59:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [June 11, 2018, 9:59am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/1 "2018-06-11T09:59:05Z")

</div>

HI,  
im running on ansible 2.4.2 and trying to get a file from sharepoint, but always gotten 401 Unauthorized error (even i confirmed that the password is correct)

fatal: [hostname → localhost]: FAILED! =\> {  
“changed”: false,  
“dest”: “filename”,  
“invocation”: {  
“module\_args”: {  
“attributes”: null,  
“backup”: null,  
“checksum”: “”,  
“client\_cert”: null,  
“client\_key”: null,  
“content”: null,  
“delimiter”: null,  
“dest”: “filename”,  
“directory\_mode”: null,  
“follow”: false,  
“force”: true,  
“force\_basic\_auth”: true,  
“group”: null,  
“headers”: null,  
“http\_agent”: “ansible-httpget”,  
“mode”: null,  
“owner”: null,  
“regexp”: null,  
“remote\_src”: null,  
“selevel”: null,  
“serole”: null,  
“setype”: null,  
“seuser”: null,  
“sha256sum”: “”,  
“src”: null,  
“timeout”: 10,  
“tmp\_dest”: null,  
“unsafe\_writes”: null,  
“url”: “[http://someurlhere/filename.txt](http://someurlhere/filename.txt)”,  
“url\_password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“url\_username”: “benny”,  
“use\_proxy”: true,  
“validate\_certs”: false  
}  
},  
“msg”: “Request failed”,  
“response”: “HTTP Error 401: Unauthorized”,  
“state”: “absent”,  
“status\_code”: 401,  
“url”: “[http://someurlhere/filename.txt](http://someurlhere/filename.txt)”,  
}

My playbook is rather simple:

- name: get the lockdown script  
get\_url:  
url: “[http://someurlhere/filename.txt](http://someurlhere/filename.txt)”,  
url\_username: “{{ url\_username }}”  
url\_password: “{{ url\_password }}”  
dest: filename  
force\_basic\_auth: yes  
force: yes  
validate\_certs: no  
delegate\_to: localhost

i can open the URL link from browser, and also tried using curl and it works (curl -u benny:mypassword -o /tmp/a.sh [http://someurlhere/filename.txt](http://someurlhere/filename.txt))

Anyone has any idea what is the cause ?

beside, my password contains special character “$”, i have tried to put them under double-quote in the url\_password field as well, but didnt work.

Thank you

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 11, 2018, 10:24am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/2 "2018-06-11T10:24:22Z")

</div>

I've seen instances where Sharepoint treated different clients  
slightly different based on the user-agent string.  
If you use "curl -A ansible-httpget .." to quickly rule that out.

Dick

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [June 12, 2018, 5:26am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/3 "2018-06-12T05:26:15Z")

</div>

Hi Dick,

thanks for the response.  
adding curl -A ansible-httpget will result in below:

STATE: DO\_DONE =\> WAITPERFORM handle 0x600057980; line 1795 (connection #0)

- STATE: WAITPERFORM =\> PERFORM handle 0x600057980; line 1811 (connection #0)
- HTTP 1.1 or later with persistent connection, pipelining supported  
\< HTTP/1.1 401 Unauthorized
- Server Microsoft-IIS/7.5 is not blacklisted  
\< Server: Microsoft-IIS/7.5  
\< SPRequestGuid: 024a709e-b9df-b0eb-e894-fb84e122f805  
\< request-id: 024a709e-b9df-b0eb-e894-fb84e122f805  
\< X-FRAME-OPTIONS: SAMEORIGIN  
\< SPRequestDuration: 10  
\< SPIisLatency: 0  
\< WWW-Authenticate: Negotiate
- NTLM handshake rejected
- Authentication problem. Ignoring this.  
\< WWW-Authenticate: NTLM  
\< X-Powered-By: [ASP.NET](http://ASP.NET)  
\< MicrosoftSharePointTeamServices: 15.0.0.4569  
\< X-Content-Type-Options: nosniff  
\< X-MS-InvokeApp: 1; RequireReadOnly  
\< Date: Tue, 12 Jun 2018 05:23:54 GMT  
\< Content-Length: 0

Any way to bypass this in ansible get\_url ?

Thank you

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [June 13, 2018, 8:38pm UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/4 "2018-06-13T20:38:53Z")

</div>

Have you tried adding  
“force\_basic\_auth : yes” to your get\_url task?

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [June 14, 2018, 3:03am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/5 "2018-06-14T03:03:22Z")

</div>

Yes, i tried to force:yes and force\_basic\_auth:yes  
i guess the header agent was the issue, but not sure on how to overwrite it

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 14, 2018, 6:10am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/6 "2018-06-14T06:10:47Z")

</div>

You have two options.

User-Agent is request header information so could use  
&nbsp;&nbsp;&nbsp;headers: "User-Agent:\<a User-Agent string\>"

According to the source code you can also use  
&nbsp;&nbsp;&nbsp;http\_agent: \<a User-Agent string\>

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [June 14, 2018, 7:08am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/7 "2018-06-14T07:08:38Z")

</div>

Hi Kai,  
yes i have tried both that but no success

get\_url:  
…  
http\_agent: “Mozilla/5.0”

headers: “User-Agent:Mozilla/5.0”

…

on the debug mode, i can see that http\_agent has changed as per what i have key in, but still gotten 401 Unauthorized.

i tried to use both parameter OR either one, but none succeed.

i guess for now, curl would be the straight forward

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 14, 2018, 7:35am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/8 "2018-06-14T07:35:08Z")

</div>

I can't help with Sharepoint since that is a product I don't use.

But if it's anal about the user-agent string you probably should use a valid one(one that exist in a agent).  
To my knowledge no agent is using just "Mozilla/5.0".

Why don't you try with the user-agent string that curl is using.

---

<div class="post-metadata">

**Author:** ![Benny\_Kusman](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@Benny\_Kusman](https://forum.ansible.com/u/Benny_Kusman)\
**Post date:** [June 14, 2018, 8:18am UTC](https://forum.ansible.com/t/get-url-always-return-401-unauthorized/27765/9 "2018-06-14T08:18:18Z")

</div>

Hi Kai,

Thanks for the quick response.  
i tried use the curl user-agent, which is curl/7.59.0  
both also return 401 unauthorized… … flusterring…
