# Weird HTTP request hijinks.

**URL:** <https://forums.plex.tv/t/weird-http-request-hijinks/51045>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [December 23, 2013, 11:15pm UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045 "2013-12-23T23:15:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [December 23, 2013, 11:15pm UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/1 "2013-12-23T23:15:56Z")

</div>

Hey guys,

&nbsp;

One of my channels has recently broken on its own overnight. &nbsp;Seems now whenever I do a HTTP.ElementFromURL request to that domain, I am only returned the following element:

```

```

Eg:

```
2013-12-24 09:01:27,261 (-4f863490) : DEBUG (networking:172) - Requesting 'http://www.animeplus.tv/popular-anime/1'
2013-12-24 09:01:28,138 (-4f863490) : INFO ( __init__ :57) - 
2013-12-24 09:01:28,139 (-4f863490) : INFO ( __init__ :77) - No shows found! Check xpath queries.
```

Previously, the same code has worked fine. &nbsp;Considering this error appeared overnight and the meta tag is seemingly redirecting me to nothing, could this be the website attempting to circumvent my http requests? &nbsp;Or something else? &nbsp;Is there any way around this? &nbsp;The actual source page include that particular meta tag so I'm not even sure where that's coming from. &nbsp;Is there a tool I can use to see whats actually going on when we do these requests?

&nbsp;

Channel code [here](https://drive.google.com/file/d/0ByaxMHEvJ7_oMFFKbHZxNktvQUk/edit?usp=sharing). &nbsp;Thanks in advance. &nbsp;

---

<div class="post-metadata">

**Author:** ![dane22](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/dane22/32/4389_2.png) [@dane22](https://forums.plex.tv/u/dane22)\
**Post date:** [December 23, 2013, 11:22pm UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/2 "2013-12-23T23:22:59Z")

</div>

The URL in a browser returned a list of Anime to me, so maybe you are blocked somehow.....

Only thing I can thing of to digest this, is low level analyzing, meaning [Wireshark](http://www.wireshark.org/)

But that will still only tell you about what is going on in your case, and not the back-end logic

/Tommy

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [December 24, 2013, 2:16am UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/3 "2013-12-24T02:16:33Z")

</div>

Thanks Tommy, &nbsp;yeah the URL works fine in a browser for me as well. &nbsp;Its only when using the HTTP request from Plex, which is what I find strange. &nbsp;The log excerpt above is the result of me calling HTML.ElementFromURL then using HTML.StringFromElement on that element. &nbsp;Then finally logging the resulting string. It appears the all I'm getting from the initial request is the quoted line above. &nbsp;I'll check out Wireshark. &nbsp;Thanks for the link.

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [January 3, 2014, 11:52am UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/4 "2014-01-03T11:52:45Z")

</div>

Ok, I'm completely stumped here. &nbsp;Would someone mind taking a look at my plugin (in the original post) and see if they can provide any insight? &nbsp;As far as I can tell, I'm doing everything right and I'm not getting anything back from my HTTP requests. &nbsp;Other channels/websites work fine using the same code? &nbsp;Is it possible that the devs behind the website can identify and block/redirect requests specifically from the Plex API?

---

<div class="post-metadata">

**Author:** ![meo](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/meo/32/4534_2.png) [@meo](https://forums.plex.tv/u/meo)\
**Post date:** [January 3, 2014, 12:55pm UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/5 "2014-01-03T12:55:39Z")

</div>

Seems like the following is happening(logged from Safari):

1. The URL is requested
2. The website returns the above HTML together with a Set-Cookie request
3. The URL is requested again but now with the cookie set from step 2.
4. The website returns a redirect(302) together with a new cookie(session id)
5. The redirected URL is requested with both cookies set from step 2 and 4.
6. The "real" webpage is returned.

Using CURL gives the same result as from the Plex API. I guess you have to build some own logic around this, it seems like a DOS(Denial Of Service) protection mechanism?&nbsp;

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [January 3, 2014, 1:44pm UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/6 "2014-01-03T13:44:06Z")

</div>

Thanks for the quick reply! &nbsp;That would make sense. &nbsp;However I was under the impression that the Plex API would handle cookies for me? &nbsp;Could you recommend another plugin that uses session id cookies for me to experiment with?

---

<div class="post-metadata">

**Author:** ![meo](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/meo/32/4534_2.png) [@meo](https://forums.plex.tv/u/meo)\
**Post date:** [January 3, 2014, 2:32pm UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/7 "2014-01-03T14:32:30Z")

</div>

> Thanks for the quick reply! &nbsp;That would make sense. &nbsp;However I was under the impression that the Plex API would handle cookies for me? &nbsp;Could you recommend another plugin that uses session id cookies for me to experiment with?

Yes you're right, the Plex API will handle the cookie part(I've must have remembered it wrong). The problem is that the HTML code is telling the browser to refresh and therefore we must do the same in the plugin.

I added the following routine to \_\_init\_\_.py:

```
def HTMLElementFromURL(url):
	request = HTTP.Request(url)

```
if 'http-equiv="refresh"' in request.content:
	request = HTTP.Request(url, cacheTime = 0)

return HTML.ElementFromString(request.content)

```
```

and replaced all calls to the standard 'HTML.ElementFromURL' with the above.

Not the nicest piece of code but it did work at least&nbsp; :)

---

<div class="post-metadata">

**Author:** ![Gerk](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/gerk/32/81980_2.png) [@Gerk](https://forums.plex.tv/u/Gerk)\
**Post date:** [January 3, 2014, 4:44pm UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/8 "2014-01-03T16:44:16Z")

</div>

It seems like their server (whoever is hosting that site) is actually not configured correctly ... they are returning raw PHP code within that request when I do a direct cURL of it ...&nbsp;

```
$ curl "http://www.animeplus.tv/popular-anime/" 
```

---

<div class="post-metadata">

**Author:** ![TehCrucible](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/tehcrucible/32/5777_2.png) [@TehCrucible](https://forums.plex.tv/u/TehCrucible)\
**Post date:** [January 3, 2014, 9:30pm UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/9 "2014-01-03T21:30:06Z")

</div>

Thanks guys; awesome work Meo. &nbsp;Works great. &nbsp;You're right, it's not pretty, but it'll do. &nbsp;Thanks a million.

---

<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 21, 2019, 12:46am UTC](https://forums.plex.tv/t/weird-http-request-hijinks/51045/10 "2019-12-21T00:46:43Z")

</div>

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