# Working with Cookies

**URL:** <https://forums.plex.tv/t/working-with-cookies/12666>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [November 24, 2011, 10:51pm UTC](https://forums.plex.tv/t/working-with-cookies/12666 "2011-11-24T22:51:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrettB](https://avatars.discourse-cdn.com/v4/letter/b/e19adc/32.png) [@BrettB](https://forums.plex.tv/u/BrettB)\
**Post date:** [November 24, 2011, 10:51pm UTC](https://forums.plex.tv/t/working-with-cookies/12666/1 "2011-11-24T22:51:58Z")

</div>

Hi all,  
  
  
  
I have a few questions about making a plug-in that uses cookies.  
  
  
  
The site I am interacting with normally writes and accesses a cookie, I have figured out where the cookie is written to with a normal browser, but where is it written to with Plex?  
  
I see HTTPCookies in Plug-in Support/Data, are they written anywhere else? If I edit the Plug-in’s HTTPCookies manually it does not work, but it works fine when I manually edit a cookie for my browser, so maybe I am looking in the wrong place.  
  
  
  
I also heard that you need to work with the cookies in both the Python file and the Site Configuration, is that true?  
  
  
  
Finally, are there were some good simple plug-in examples that include working with cookies?  
  
  
  
Thanks for all your help!

---

<div class="post-metadata">

**Author:** ![mikedm139](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mikedm139/32/96909_2.png) [@mikedm139](https://forums.plex.tv/u/mikedm139)\
**Post date:** [November 24, 2011, 11:20pm UTC](https://forums.plex.tv/t/working-with-cookies/12666/2 "2011-11-24T23:20:31Z")

</div>

> [@](#):
>
> Hi all,  
>   
> I have a few questions about making a plug-in that uses cookies.  
>   
> The site I am interacting with normally writes and accesses a cookie, I have figured out where the cookie is written to with a normal browser, but where is it written to with Plex?  
> I see HTTPCookies in Plug-in Support/Data, are they written anywhere else? If I edit the Plug-in's HTTPCookies manually it does not work, but it works fine when I manually edit a cookie for my browser, so maybe I am looking in the wrong place.  
>   
> I also heard that you need to work with the cookies in both the Python file and the Site Configuration, is that true?  
>   
> Finally, are there were some good simple plug-in examples that include working with cookies?  
>   
> Thanks for all your help!

  
  
  
It depends on what you need to do with the cookies. Often, just catching and passing on the cookies is sufficient. You can catch cookies using the framework's function:  

```auto

cookies = HTTP.CookiesForURL(YOUR_URL)

```

  
You can include them in your HTTP requests, MediaContainers or ObjectContainers by specifying:  

```auto

httpCookies=cookies

```

  
or you can do it all in one step like the YouTube plugin does:  

```auto

dir = MediaContainer(httpCookies=HTTP.CookiesForURL('http://www.youtube.com/'))

```

  
  
YouTube relies heavily on cookies so you can see it used there quite a bit. [https://github.com/p.../YouTube.bundle](https://github.com/plexinc-plugins/YouTube.bundle)  
  
I don't believe that the framework accomodates editing the contents of cookies. You might be able to pass your own custom cookie using the above 'httpCookies=' format, or perhaps sending a custom header would work, e.g.  

```auto

page = HTML.ElementFromURL(your_url, headers=YOUR_CUSTOM_HEADERS)

```

  
  
  
The necessity to work with cookies in the site config as well as the python code will depend on the how the website uses the cookies. I believe the [4oD site config](https://github.com/plexinc-plugins/SiteConfigurations.bundle/blob/master/Contents/Resources/4oD.xml) might use cookies but I believe the plug-in is geoblocked so I can't really comment on the specifics. Site configs are not my strong suit by any stretch.

---

<div class="post-metadata">

**Author:** ![sarava49\_1](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@sarava49\_1](https://forums.plex.tv/u/sarava49_1)\
**Post date:** [January 8, 2015, 7:02pm UTC](https://forums.plex.tv/t/working-with-cookies/12666/3 "2015-01-08T19:02:28Z")

</div>

First off, sorry for resurrecting this thread, but I couldn't find anywhere else information on the topic.

I can't get the HTTP.CookiesForURL to work. I've tried with websites that certainly use cookies but the result of the function always come back as "None". Is this function still operational? Are there any settings that have to be configured to enable the use cookies on channels?

Thank you!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 20, 2019, 9:27pm UTC](https://forums.plex.tv/t/working-with-cookies/12666/4 "2019-12-20T21:27:48Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
