简体   繁体   中英

how to fix python request error "Expecting value"

i'm trying to get the json response of couple of product ids page. I used this

Python : how to set parameters for python request

to succesfully query a word response but I don't know why query by product id is not working. I started with with this

this is actual url to the product

https://www.walmart.com/ip/Breyers-CarbSmart-Frozen-Dairy-Dessert-Chocolate-48-oz/10898747

so I started with this code

prodID = '10898747'


url = 'https://www.walmart.com/ip/'

params = {
    
    'product_id': prodID,

}

data = requests.get(url, params=params).json()
print(data)

but it's produces this error

Expecting value: line 1 column 1 (char 0)

what am I doing wrong and how can I fix this?

The url is not returning a valid json object.

Going there in my browser yields a 404: https://www.walmart.com/ip/?product_id=743876032

And running it from a fiddle, it returns some sort of forbidden string https://repl.it/repls/BossyHoneydewMicrostation

In other words, the problem is not in your code but the request is not working.

To prevent such errors, check the response: How to determine if my Python Requests call to API returns no data

try:
    response = response.json
except ValueError:
    ...

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