浏览器 headers 转换
import re headers=''' Accept: application/json, text/javascript, */*; q=0.01 Accept-Encoding: gzip, deflate, br Accept-Language: zh-CN,zh;q=0.9 Content-Type: application/json Host: ccpce-cn.consumer.huawei.com Origin: https://consumer.huawei.com Referer: https://consumer.huawei.com/cn/support/warranty-query/ Sec-Fetch-Mode: cors Sec-Fetch-Site: same-site User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36 ''' header='' for i in headers: if i =='\n': i="',\n'" header+=i header=re.sub(': ',"': '",header) ret=header[2:].replace(' ','')+'\'' print(ret[:-4]) ''' 'Accept':'application/json,text/javascript,*/*;q=0.01', 'Accept-Encoding':'gzip,deflate,br', 'Accept-Language':'zh-CN,zh;q=0.9', 'Content-Type':'application/json', 'Host':'ccpce-cn.consumer.huawei.com', 'Origin':'https://consumer.huawei.com', 'Referer':'https://consumer.huawei.com/cn/support/warranty-query/', 'Sec-Fetch-Mode':'cors', 'Sec-Fetch-Site':'same-site', 'User-Agent':'Mozilla/5.0(WindowsNT10.0;WOW64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/78.0.3904.108Safari/537.36' '''