- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
getresponse
在读取 HTML 请求的 header 时发出许多 recv
调用。它实际上为每个字节发出 recv
,这会导致许多系统调用。如何优化?
我在 Ubuntu 机器上用 strace dump 进行了验证。
示例代码:
conn = httplib.HTTPConnection("www.python.org")
conn.request("HEAD", "/index.html")
r1 = conn.getresponse()
跟踪转储:
sendto(3, "HEAD /index.html HTTP/1.1\r\nHost:"..., 78, 0, NULL, 0) = 78
recvfrom(3, "H", 1, 0, NULL, NULL) = 1
recvfrom(3, "T", 1, 0, NULL, NULL) = 1
recvfrom(3, "T", 1, 0, NULL, NULL) = 1
recvfrom(3, "P", 1, 0, NULL, NULL) = 1
recvfrom(3, "/", 1, 0, NULL, NULL) = 1
...
最佳答案
r = conn.getresponse(buffering=True)
在 Python 3.1+ 上没有 buffering
参数(这是默认值)。
关于Python:httplib getresponse 发出许多 recv() 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14519829/
“AAaarg”!请帮忙!!! 这是我正在尝试做的... 我有一个 Django 站点 site1,它需要访问另一个服务 site2 的 API。然而,为了做到这一点,site1 需要使用它自己的登录
以下代码引发错误“socket.gaierror: [Errno -2] Name or service not known”。 import httplib, urllib attrs = urll
我正在尝试获取似乎重定向不止一次的页面的最终 URL。在您的浏览器中尝试这个示例 URL,并将其与我的代码片段底部的最终 URL 进行比较: Link that redirects more than
我有一个在端口 6868 上运行的本地服务器。从技术上讲,它是使用 Express 构建的由 Node.js 驱动的微型站点。它实际上有一个“/push” Controller 读取一些数据并写入控制
我使用带有私钥的httplib.HTTPSConnection: h = httplib.HTTPSConnection(url, key_file='../cert/priv.pem', cert_
我有以下代码要使用: def createCon(host,auth): con = httplib.HTTPSConnection(host) return con def _rea
我有一个脚本,它使用 Python 中的 httplib 获取互联网上很多页面的 HTTP header 。 我的问题是关于 specific domain (可能还有其他人),httplib 引发异
我正在尝试使用 httplib 将信用卡信息发送到 authorize.net。当我尝试发布请求时,我得到以下回溯: File "./lib/cgi_app.py", line 139, in run
我正在尝试弄清楚如何通过代理将数据发送到服务器。我希望这可以通过 tor 实现,但是因为 tor 使用 SOCKS,所以使用 httplib 显然不可能(如果我错了请纠正我) 这是我现在拥有的 imp
我正在使用 python 为 elgg 编写一个 REST 客户端,即使请求成功,我也会得到以下响应: Traceback (most recent call last): File "testc
我正在实现一个从各种服务器获取网页的小服务。我需要能够配置不同类型的超时。我尝试过使用套接字的 settimeout 方法,但它并不完全符合我的要求。这是问题所在。 我需要指定初始 DNS 查找的超时
我正在使用 httplib 向服务器发布帖子。我正在拿回 303 See Other。我如何查看重定向消息“303 See Other”并没有真正帮助。 谢谢 conn1 = httplib.HTTP
问题是这样的: 我有一个 Django 网站。 我正在尝试使用 httplib 向站点发送 POST 请求。 当我尝试发送 POST 请求时,Django 需要 CSRF token 。 如何才能毫无
我想编写一个 python 脚本,它将请求 reddit 帖子 url,转到页面,使用指定帐户登录并为帖子点赞和注销。 A) 这可以用 python 完成吗? B) 我该怎么做?如果您可以提供很棒的代
我想使用 HTTPS 协议(protocol)从 python 的 httplib 库发送 Get 请求。 我已经浏览了多个答案,建议如何在使用 http 协议(protocol)时执行此操作,但它们
我正在使用 suds 0.3.6。创建 suds 客户端时,随机出现错误: httplib.py,_read_status(),第 355 行,类 httplib.BadStatusLine' 这是用
我发现 httplib.HTTPSConnection 不执行自动服务器证书检查。据我了解的问题,我需要手动添加该功能,例如通过按照描述对此类进行子类化 here . 由于我使用的是 Python2.
默认情况下,httplib 调试发送、 header 和回复信息作为 logger.info 返回, 如何将发送、 header 和重播显示为调试信息的一部分? import requests imp
我想通过 HTTP GET 请求将数据发送到我的服务器,每 1-2 秒一次。 我应该每次都创建一个新连接,还是应该保持连接打开并继续通过同一连接发送请求?如果我采用后一种方法,httplib 会保持连
httplib.HTTPException 是否有错误代码?如果是这样,我如何从异常实例中获取它们?感谢您的帮助。 最佳答案 httplib 模块不使用异常来传达 HTTP 响应,只是真正的错误(无效
我是一名优秀的程序员,十分优秀!