问题描述:在Python中组装请求头进行post请求时报以下错误:
raise InvalidHeader("Invalid return character or leading space in header: %s" % name)
requests.exceptions.InvalidHeader: Invalid return character or leading space in header: Cookie
解决方法:出现此报错的原因是header请求头不能有空格
HEADERS = {
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*',
'Accept-Encoding': 'gzip, deflate',
'Cookie': ' JSESSIONID=00233fffff'
}
修改后为
HEADERS = {
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*',
'Accept-Encoding': 'gzip, deflate',
'Cookie': 'JSESSIONID=00233fffff'
}