使用requests遇到的坑

Invalid header name b':authority

headers = {':authority': 'wx1.sinaimg.cn',
':method': 'GET',
':path': '/thumb150/006pn7pXly1gnc4kwcsb3j30c83cmk6z.jpg',
':scheme': 'https',
'accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7',
'cache-control': 'no-cache',
'pragma': 'no-cachee',
'referer': 'https://weibo.com/',
'sec-ch-ua': '"Chromium";v="88", "Google Chrome";v="88", ";Not A Brand";v="99"',
'sec-ch-ua-mobile': '?0',
'Sec-Fetch-Dest': 'image',
'Sec-Fetch-Mode': 'no-cors',
'Sec-Fetch-Site': 'cross-site',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.3'
}

只要将请求头中key值之前带有的“:”去掉,然后去请求就成功了,其它按正常思路走就可以了。

 
 
喜欢艺术的码农
原文地址:https://www.cnblogs.com/zjhgx/p/14383730.html