'error': 'Bad Request', 'message': "JSON parse error: Unrecognized token 'channel'

#遇到的问题,报错:{'timestamp': 1689648959518, 'status': 400, 'error': 'Bad Request', 'message': "JSON parse error: Unrecognized token 'channel': was expecting ('true', 'false' or 'null'); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'channel': was expecting ('true', 'false' or 'null')\n at [Source: (PushbackInputStream); line: 1, column: 9]", 'path': '/position/search'}

代码:

import requests

headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
         'Cookie':'XSRF-TOKEN=42c886c0-fc79-475f-b5c7-67e61c5b70c4; prefered-lang=zh; SESSION=MjU3RTU4OTBDNzFBMTNERDc4MjBCODg0OTJFREZGREE=; isg=BJ2dqBjhpYm3JEG2WAFJJsyLrHmXutEMpTIWSV9i1vQjFr1IJws13GrHQAoQ1unE; l=fBrUP5MPN6KN0d5iBOfwPurza77OjIRAguPzaNbMi9fPOA5B5_aPW1_714Y6CnGVFsZXR3lDK4dwBeYBq_C-nxvT3mr0xoHmndLHR35..; tfstk=cto1B3bBo1f_50Kcj59ERKvzlfEAasOQKFNtCQdrQW029Hh09sDR47MoVqf30-eC.',
         'Accept-Encoding':'gzip, deflate, br',
         'Accept':'application/json, text/plain, */*',
         'Referer':'https://talent.alibaba.com/off-campus/position-list?lang=zh',
         'Content-Type':'application/json',
         'Path':'/position/search?_csrf=42c886c0-fc79-475f-b5c7-67e61c5b70c4',
         'Authority':'talent.alibaba.com',
         'Method':'POST',
         'Sec-Ch-Ua':'"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"',
         'Sec-Fetch-Mode':'cors',
         'Bx-V':'2.2.3',
         'Sec-Fetch-Site':'same-origin'
         }
url='https://talent.alibaba.com/position/search?_csrf=42c886c0-fc79-475f-b5c7-67e61c5b70c4'
data={
    "channel":"group_official_site",
    "language":"zh",
    "batchId":"",
    "categories":"",
    "deptCodes":[],
    "key":"",
    "pageIndex":1,
    "pageSize":10,
    "regions":"",
    "subCategories":""
}
session=requests.session()
html=session.post(headers=headers,url=url,data=data).json()
print(html)

#data的数据类型不一样呢还是,求帮忙?

header字典的键有点问题,这不应该就是请求对象嘛?怎么能放在首部

import requests
import json

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
    'Cookie': 'XSRF-TOKEN=42c886c0-fc79-475f-b5c7-67e61c5b70c4; prefered-lang=zh; SESSION=MjU3RTU4OTBDNzFBMTNERDc4MjBCODg0OTJFREZGREE=; isg=BJ2dqBjhpYm3JEG2WAFJJsyLrHmXutEMpTIWSV9i1vQjFr1IJws13GrHQAoQ1unE; l=fBrUP5MPN6KN0d5iBOfwPurza77OjIRAguPzaNbMi9fPOA5B5_aPW1_714Y6CnGVFsZXR3lDK4dwBeYBq_C-nxvT3mr0xoHmndLHR35..; tfstk=cto1B3bBo1f_50Kcj59ERKvzlfEAasOQKFNtCQdrQW029Hh09sDR47MoVqf30-eC.',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept': 'application/json, text/plain, */*',
    'Referer': 'https://talent.alibaba.com/off-campus/position-list?lang=zh',
    'Content-Type': 'application/json',
}

url = 'https://talent.alibaba.com/position/search'
csrf = '42c886c0-fc79-475f-b5c7-67e61c5b70c4'

data = {
    "channel": "group_official_site",
    "language": "zh",
    "batchId": "",
    "categories": "",
    "deptCodes": [],
    "key": "",
    "pageIndex": 1,
    "pageSize": 10,
    "regions": "",
    "subCategories": ""
}

session = requests.session()
response = session.post(url, headers=headers, json=data, params={'_csrf': csrf})
html = response.json()
print(html)


不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^