i_ucprice = [[id, price], [id, price], [id, price], [id, price]]
for ids in id_ucprice:
post_data = {
'price': ids[1],
'overpriced_email_price_change': False,
'apply_to_all': False,
}
for i in range(ids[0]):
response = requests.post('api{ids[0]}/pricing', cookies=cookies, headers=headers, json=post_data)
update_data = json.loads(response.text)
print(update_data)
response_price = update_data['priceCents']
r_item = update_data['name']
r_id = update_data['id']
ids[0]
if response_price == ids[1]:
print(style.MAGENTA + f'[{datetime.now()}] => Updated Price: {response_price/100:.2f} | ID: {r_id} | Item: {r_item}')
我有一个嵌套的列表,作为[[id, price], [id, price], [id, price], [id, price]]
,我需要迭代[0]
和[1]
值,分别在请求url和json数据中使用。我不能得到变量在请求url中使用,但json数据似乎工作良好
你试过让url f-string吗?
response = requests.post(f'api{ids[0]}/pricing', cookies=cookies, headers=headers, json=post_data)