to reproduce the situation
from urllib.request import Request, urlopen
site= 'https://www.ssense.com/en-hk/women/dresses'
hdr = {'User-Agent': 'Mozilla/5.0'}
req = Request(site,headers=hdr)
page = urlopen(req)
print(page.getcode())
the above return response 200, while request return 403 below
import requests
page = requests.get('https://www.ssense.com/en-hk/women/dresses',headers={'User-Agent': 'Mozilla/5.0'})
print(page.status_code)
Note: A funny issue is after request return 403, urlopen return 403 when executed immediately. Waiting for a few minutes, urlopen gives 200 again
I would like to ask
- is it safe to use urlopen in this case? as most people recommend request over urlopen
- if possible, please answer why this happen? as people mentioned they are similar
Thank you for your help!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…