linuxmint / hypnotix

An M3U IPTV Player
1.25k stars 168 forks source link

Xtream API - Error 403 (Forbidden) if requests sent without user-agent [with solution] #274

Open diegobenincasa opened 1 year ago

diegobenincasa commented 1 year ago

I found a bug where Hypnotix is unable to authenticate to Xtream API if user-agent is not sent in header request. But as I tried the URL in browser and it worked out of the box, I gave a try looking for the issue - and found it: Xtream API refuses to authenticate if User-Agent is not sent as a request header.

But I found a really easy workaround (not with time now to create a pull request).

  1. In file xtream.py, method authenticate(self), just at the start of try block, add: headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'} And at the next line (where requests takes place), add a new parameter headers=headers.

  2. Also in the same xtream.py file, in method _get_request(self, URL: str, timeout: Tuple = (2,15)), add the same headers definition (as described upwards) before the try block and, just after it, in the requests call, add the new parameter headers=headers.

That should do the trick!

superolmo commented 1 year ago

Could you test the Pull Request I have with your xtream account and write a comment if it works for you? Instructions to test PR in case you are not aware: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally?tool=webui

diegobenincasa commented 1 year ago

@superolmo Sorry for my delayed response. No, it does not work either. I'll test with user-agent set-up inside code again and see if it works. I'll try to post a new status soon.