简体   繁体   中英

How can I use response data from a post request to compare to the posted data in python

    'price': 16000,
    'overpriced_email_price_change': False,
    'apply_to_all': False,
}

response = requests.post('apiurl', cookies=cookies, headers=headers, json=post_data)

response_data = json.loads(response.text)


def check_status(post_data,response_data):
    if 'priceCents' == 'price':
        print("updated success")
    else:
        print("error updating")

so I have my post request working because when I had print(response_data['priceCents') it would print the exact amount in price but I want to have a function where it checks if the response is equal to the posted data.

Have you tried the following?

    'price': 16000,
    'overpriced_email_price_change': False,
    'apply_to_all': False,
}

response = requests.post('apiurl', cookies=cookies, headers=headers, json=post_data)

response_data = json.loads(response.text)


def check_status(post_data,response_data):
    if response_data['priceCents'] == post_data['price']:
        print("updated success")
    else:
        print("error updating")
def check_status(post_data,response_data):
    if 'priceCents' == 'price':
        print("updated success")
    else:
        print("error updating")

You are trying to compare two string values, if i'm not much mistaken. If that is the case, "update success" will never happen.

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