[英]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.所以我有我的帖子请求工作,因为当我有
print(response_data['priceCents')
时,它会打印price
的确切金额,但我想要一个函数来检查响应是否等于发布的数据。
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.如果是这样,
"update success"
将永远不会发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.