python - Python请求响应很慢,不等于cURL
问题描述
这是一个奇怪的活动,我从 cURL 和 Python 的requests
模块中得到了不同的响应。此外,Python 非常慢:cURL 大约需要 6 秒,但 Python 是 2 分钟。
我的 cURL 命令是:
curl -L -s -k --request GET \
--url "https://$1/api/maintenance/maintenance/dual_image_config" \
--header 'Cache-Control: no-cache' \
--header 'Accept-Encoding: gzip, deflate, sdch' \
--header 'Content-Type: application/json' \
--header 'Connection: keep-alive'
卷曲响应是:
{ "state_1": "Active", "state_2": "stand-by", "current_active_image": "Image-1", "id": 1}
我的 Python 代码是:
import requests, sys
DEFAULT_HEADER = {"Accept-Encoding": "gzip, deflate, br",
"Cache-Control": "no-cache",
"Connection": "keep-alive",
"Content-Type": "application/json",
"X-Requested-With": "XMLHttpRequest"}
url = "https://{0}/api/maintenance/maintenance/dual_image_config".format(sys.argv[1])
response = requests.get(url="", data=None, headers=DEFAULT_HEADER , verify=False)
Python响应response.text
是:
'0121\r\n{ "state_1": "Active", "state_2": "stand-by", "current_active_image": "Image-1", "id": 1}\r\n0\r\n\r\n'
它将在开始和开始时有 0121\r\n & \r\n0\r\n\r\n,我尝试更改请求标头和编码,但它不起作用,为什么它得到不同的响应,等等减缓 ?
解决方案
推荐阅读
- azure - Azure 预留实例 - 检查分配
- excel - 编译 ExcelDNA解包
- typescript - 对于沙盒,有没有办法直接在浏览器中运行 TypeScript?
- python - Python Tkinter StringVar() 未打包在 JSON 请求中
- ios - 禁用或更新 Apple ID 设置,或在模拟器上单击“Not Now”
- c# - 从继承自另一个类的类中获取数据
- javascript - 通过遍历列表来更改图像的 src
- java - Java 扫描器和 if-else 语句
- php - php钠函数中的ENCONDING CHARACTERS问题
- android - 如何修复 android.widget.TextView() 需要 api 21 错误