代码如下
# 导入request包
import requests
# 请求URL
URL3='https://blog.csdn.net//phoenix/web/v1/article/like'
# 入参
data3={'articleId':109552419}
# 请求头
headers3={'cookie':'uuid_tt_dd=10_30308678820-1713771851124-190368; loginbox_strategy=%7B%22taskId%22%3A349%2C%22abCheckTime%22%3A1714471567846%2C%22version%22%3A%22exp11%22%2C%22blog-threeH-dialog-exp11tipShowTimes%22%3A1%2C%22blog-threeH-dialog-exp11%22%3A1714471567847%7D; UserName=2301_76297780; UserInfo=3fa314d641fc461d918439b172719f20; UserToken=3fa314d641fc461d918439b172719f20; UserNick=Cindy%E8%BE%9B%E8%92%82; AU=6A4; UN=2301_76297780; BT=1714471648682; p_uid=U010000; Hm_up_6bcd52f51e9b3dce32bec4a3997715ac=%7B%22islogin%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%222301_76297780%22%2C%22scope%22%3A1%7D%7D; c_first_ref=www.baidu.com; c_segment=0; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1713771953,1714471568,1714974879; dc_sid=bd2fdd7d00db071e1271d983fc49f000; 2301_76297780comment_new=1715194617723; dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MzYyMjY5MywiZXhwIjoxNzE2MDAyOTQ2LCJpYXQiOjE3MTUzOTgxNDYsInVzZXJuYW1lIjoiMjMwMV83NjI5Nzc4MCJ9.DrU7pnadW6pQYP1BHQRsniYY94vjAFwL8qZ6noIcqbk; historyList-new=%5B%5D; csrfToken=oCeF2G3gBjVfMRom1Dn_jm5v; management_ques=1715670382919; creative_btn_mp=3; fe_request_id=1715678405635_1120_3692471; Hm_lvt_ec8a58cd84a81850bcbd95ef89524721=1715681642; _clck=1ycbxns%7C2%7Cfls%7C0%7C1573; dc_session_id=10_1715737860895.713217; log_Id_click=399; _clsk=15bz9y8%7C1715740085605%7C7%7C0%7Cq.clarity.ms%2Fcollect; c_first_page=https%3A//blog.csdn.net/qq_35096008/article/details/109552419; c_dsid=11_1715740767547.883891; Hm_lpvt_ec8a58cd84a81850bcbd95ef89524721=1715740768; creativeSetApiNew=%7B%22toolbarImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20230921102607.png%22%2C%22publishSuccessImg%22%3A%22https%3A//img-home.csdnimg.cn/images/20240229024608.png%22%2C%22articleNum%22%3A100%2C%22type%22%3A2%2C%22oldUser%22%3Atrue%2C%22useSeven%22%3Afalse%2C%22oldFullVersion%22%3Atrue%2C%22userName%22%3A%222301_76297780%22%7D; __gads=ID=0e92228d9fb889c0:T=1713771853:RT=1715740768:S=ALNI_MZDxtnPZPoGI8XSEIKuN-3vBwl2-w; __gpi=UID=00000df5c4948666:T=1713771853:RT=1715740768:S=ALNI_Mae3444nLORiX5Fr1BbtMp-yFmBbA; __eoi=ID=5467efae1e9b2601:T=1713771853:RT=1715740768:S=AA-AfjaS125ilsTH-6jYyr4zsBqj; waf_captcha_marker=a80ae7ea62f21fee2c379df2cdd46cd342525ed5375faada2ea8264f0ea1d0b2; c_pref=https%3A//www.baidu.com/link; c_ref=https%3A//blog.csdn.net/qq_35096008/article/details/109552419; c_page_id=default; log_Id_pv=226; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1715740795; log_Id_view=8404; dc_tos=sdia2l','host':'blog.csdn.net','origin':'https://blog.csdn.net','referer':'https://blog.csdn.net/qq_35096008/article/details/109552419','User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
}
# 发起post请求
res3=requests.post(URL3,data=data3,headers=headers3)
# 响应文本
print(res3.text)
# 响应码
print(res3.status_code)
运行结果
有点困惑的是公司的网站接口我拿postman可以跑通,但是用python始终不行,headers全传也会报错。同样的代码跑csdn接口就是好的。有大佬知道原因的话请告诉我,谢谢啦。