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

Time:06-27

    '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.

CodePudding user response:

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")

CodePudding user response:

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.

  • Related