我正在创建一个python应用程序,可以将亚马逊商品添加到购物车。但是,Amazon正在使用内部服务器错误来响应请求。我做了一个与javascript扩展相同的应用程序,它的工作证明了发送的数据是正确的。因此,我很想知道为什么尽管正确发送了所有数据,但是服务器对两个应用程序的响应却不同。出于明显的原因,我在以下代码中更改了cookie,以下是两个代码: JavaScript代码:
data = 'dealId='+dealid+'&itemId='+asin+'&clientId=goldbox_mobile_pc'
resp = "";
$.ajax({
url: 'https://www.amazon.in/gp/deal/ajax/v2/claimDeal.html',
type: 'post',
data: data,
beforeSend: function (x) {
x.setRequestHeader("x-csrftoken", token);
},
success: function (data, textStatus, jQxhr) {
console.log(data)
},
error: function (jqXhr, textStatus, errorThrown) {
console.log(errorThrown);
}
});
import requests
from requests.cookies import cookiejar_from_dict
#creating a session
session = requests.Session()
#getting the csrf token. function is not shown in this code but it exists
csrf=getCsrf()
#sending cookies for loggging in
session.cookies={"ubid-acbin":"261-47212800-4332916","x-acbin":"unH4
KUpytXNLkPMKJm0DvSdgqMm@Gc?JDIwN2SJ@wmBDeBirSx6mHDHnHcljzy7rJ"}
session.cookies = cookiejar_from_dict(session.cookies)
#setting headers
session.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.61 Safari/537.36',
"x-csrftoken": csrf
}
#sending request
m=session.post('https://www.amazon.in/gp/deal/ajax/v2/claimDeal.html', data='dealId=d9ca05bf&itemId=B086Z933SS&clientId=goldbox_mobile_pc')
print(m.content)