将python的requests请求转为curl命令行格式, 方便调试
import curlify
import requests
data = {
"wd": "hello"
}
url = 'http://www.baidu.com/s'
response = requests.get(url=url, data=data, headers={
'Accept': 'text/html,application/xhtml+xml',
})
print(curlify.to_curl(response.request))
执行结果:
$ python3 a.py
curl -X GET -H 'Accept: text/html,application/xhtml+xml' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'Content-Length: 8' -H 'Content-Type: application/x-www-form-urlencoded' -H 'User-Agent: python-requests/2.25.1' -d wd=hello http://www.baidu.com/s
(完)