Traceback (most recent call last): File "D:\Program Files\JetBrains\PyCharm 2020.1\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec exec(exp, global_vars, local_vars) File "<input>", line 1, in <module> File "<string>", line 12, in vertifyName File "C:\ProgramData\Anaconda3\envs\env_cv2_cp38\lib\site-packages\requests\api.py", line 115, in post return request("post", url, data=data, json=json, **kwargs) File "C:\ProgramData\Anaconda3\envs\env_cv2_cp38\lib\site-packages\requests\api.py", line 59, in request return session.request(method=method, url=url, **kwargs) File "C:\ProgramData\Anaconda3\envs\env_cv2_cp38\lib\site-packages\requests\sessions.py", line 573, in request prep = self.prepare_request(req) File "C:\ProgramData\Anaconda3\envs\env_cv2_cp38\lib\site-packages\requests\sessions.py", line 471, in prepare_request cookies = cookiejar_from_dict(cookies) File "C:\ProgramData\Anaconda3\envs\env_cv2_cp38\lib\site-packages\requests\cookies.py", line 537, in cookiejar_from_dict cookiejar.set_cookie(create_cookie(name, cookie_dict[name])) TypeError: string indices must be integers
时间: 2023-06-30 17:10:17 浏览: 244
这个错误一般是因为请求中的某个参数值不是字典类型而导致的。请检查 payload 参数是否正确构造为字典类型。你可以尝试将 payload 参数中的 JSON 字符串转换为字典类型,如下所示:
```python
import requests
url = "https://crm.baidu.com/polaris-web/sme-cust/verify/verifyName"
payload = {"name": "三本树(上海)教育科技有限公司"}
headers = {
"isajax": "true",
"Cookie": "BIDUPSID=A09C98D9802D21EDCE9B8A4490EC5CE2; PSTM=1684252632; BAIDUID=A09C98D9802D21ED17765F505D625969:FG; BAIDUID_BFESS=A09C98D9802D21ED17765F505D625969:FG; ZFY=qt8fKnqLflisaA:BUnKqV:Awo8rk7t:AVWJCPMo5050PfU:C; HR_SIGN=UC_70a2711cf0144243891424851662987554571; Hm_lpvt_2188c29772eeba07a9fce63dc27d321c=1685026331; RT=\"z; tk=313027c567ba2913015e3f047346a9b2-1685026351022",
"User-Agent": "Apifox/1.0.0 (https://apifox.com)",
"Content-Type": "application/json;charset=UTF-8",
}
response = requests.post(url, headers=headers, json=payload)
print(response.text)
```
阅读全文