xteve-repo / scripts

Various scripts from the xTeVe Discord channel
1 stars 1 forks source link

CUID_IncExclude.py – headers are not set #1

Open wm-tbourne opened 3 years ago

wm-tbourne commented 3 years ago

https://github.com/xteve-repo/scripts/blob/master/CUID_IncExclude.py#L16

I believe the above line should be:

response = urllib.request.urlopen(req)

Seems to work as expected when I make the change

MCTyler commented 3 years ago

Has always worked for all of us like this....This seems very isolated.... # Get M3U file from provider response = urllib.request.urlopen(url) data = response.read() providerM3uFile = data.decode('utf-8') We need a few tests to make sure it works as expected for all. @marmei

MCTyler commented 3 years ago

I just tested a old script I had and replaced (url) with (req) and the script would not run.....

Note: This Script requires Python 3 in the set Path.

wm-tbourne commented 3 years ago

@MCTyler weird – only works for me if I change out url to req`. I'm also running this using Python 3. 🤷

wm-tbourne commented 3 years ago

See this stack overflow post https://stackoverflow.com/a/36532952.. to me it seems like if you're passing in URL you're completely ignoring the line where you're setting req. If you're not passing in req what is it being set for?

url = "https://www.example.com"
# pretend to be a chrome 47 browser on a windows 10 machine
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"}
req = urlRequest.Request(url, headers = headers)
# open the url
x = urlRequest.urlopen(req)
# get the source code
sourceCode = x.read()
MCTyler commented 3 years ago

Your right, if Provider doesn't care what Header is used, like mine, then it just works...If Provider blocks some User-Agents then your edit will resolve that with the proper Header...Change meets my approval..... @marmei

MCTyler commented 3 years ago

I think user-agent should remain VLC since it's universally excepted.... #Headers headers = {'User-Agent': 'VLC'}

MCTyler commented 3 years ago

https://github.com/xteve-repo/scripts/compare/master...MCTyler:patch-1

xteve-repo commented 3 years ago

Pull request submitted by @MCTyler was approved --LeeD

taylorbourne commented 3 years ago

Switching to my personal account – @MCTyler thanks for pushing this through! I know it's not a huge deal but will help if someone runs into 403s using this script.. and I totally agree that VLC as User-Agent should work fine here.

MCTyler commented 3 years ago

Great...Can you close this Please. @taylorbourne