简体   繁体   中英

Getting data from website via requests.get and receiving 401 response

I'm trying to get JSON with products details from the website https://www.highspiritsuae.com/shop?Collection=WINE by sending request.get .

I'm very new in interaction with web, however by using of developer tools in Chrome was able to find element that gives this JSON and look at headers, Chrome sends to get it.

I have created few rows of code, however, receive 401 as a result. As per google it means authorization issue, but when I open website through browser it does not require any login/password.


url ='https://www.highspiritsuae.com/_api/wix-ecommerce-storefront-web/api?o=getFilteredProducts&s=WixStoresWebClient&q=query'
#url = 'https://www.highspiritsuae.com/_serverless/analytics-reporter/facebook/event'

t = requests.get(
    
    url,

     params = {
     "isPremium": "true",
     "metaSiteId": "fc3611a3-f8bf-4a5d-8979-51b24f693fc1",
     "origin": "Stores",
     "userId": "92f732fb-9623-461f-8e2b-40e2d1e9a49a",
     "visitorId": "f2b49b1d-3248-4551-af5f-94ae17ece5c0",
     "_internalEventId": "85640bb5-83d4-425f-98d3-807c255741cc",
     "eventName": "AddProductImpression"
       },
    
    headers= {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"}
    )

print(t)

Will really appreciate if someone can have a look and advise what I'm missing.

how to emulate this request?

What am I suggesting is to open network of browser devtools and see if there is no an authorization header in browser request then it probably uses cookies. Easy way to emulate the request is do right click on request and copy as cURL then using cURLConverter you can convert your request to Python's requests and compare with your code

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM