archugs / NSE-Live-Market

Scrapes data from NSE India website
2 stars 1 forks source link

UnicodeDecodeError #1

Open ketankr9 opened 7 years ago

ketankr9 commented 7 years ago

Error I get when I run the python3 NSE-Top10.py Traceback (most recent call last): File "NSE-Top10.py", line 67, in <module> data['gainers'] = parse_URL(topGainersUrl) File "NSE-Top10.py", line 14, in parse_URL parsed_json = json.loads(response.read().decode('utf-8')) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

gabrieaj commented 7 years ago

change this line: req = urllib.request.Request(url, headers={"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8", "Accept-Encoding": "gzip,deflate,sdch", "User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36"})

to req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})

This worked for me in python 3.6