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:
cookies = HTTP.CookiesForURL(YOUR_URL)
You can include them in your HTTP requests, MediaContainers or ObjectContainers by specifying:
httpCookies=cookies
or you can do it all in one step like the YouTube plugin does:
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.
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.
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!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.