# Add cookie handling to the open\_url method in the urls lib

**URL:** <https://forum.ansible.com/t/add-cookie-handling-to-the-open-url-method-in-the-urls-lib/23974>\
**Category:** Ansible Developer\
**Created:** [March 15, 2017, 5:19am UTC](https://forum.ansible.com/t/add-cookie-handling-to-the-open-url-method-in-the-urls-lib/23974 "2017-03-15T05:19:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig\_Smith](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@Craig\_Smith](https://forum.ansible.com/u/Craig_Smith)\
**Post date:** [March 15, 2017, 5:19am UTC](https://forum.ansible.com/t/add-cookie-handling-to-the-open-url-method-in-the-urls-lib/23974/1 "2017-03-15T05:19:38Z")

</div>

Hi,

I am trying to avoid using a third party http libraries in a module I am building for a system that requires cookie handling. In open\_url’s current implementation I receive the following return code and message:

`urllib2.HTTPError: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop. The last 30x error message was:`

Adding the urllib2.HTTPCookieProcessor handler like below:

`handlers.append(urllib_request.HTTPCookieProcessor)`

Resolves this issue and results in a successful 200 return code.

I would like to do two things:

1. Validate that this is an acceptable fix for my issue
2. Identify if something for this is already in the works or if I should submit a pull request with my proposed fix.  
Assuming a pull request is the appropriate course of action, does it make sense to make an additional param for open\_url to enable this functionality or to just add it as a handler irregardless or the need?

Thanks in advance for feedback and guidance!

-Craig
