Pycurl 在终端中保持打印
我是一个初学者,使用 Python 和 Pycurl 进行网页压力测试。然而,pycurl 不断在终端中打印返回的 html,这使得压力测试花费的时间比应有的时间更长。下面发布了我正在使用的一个这样的 pycurl 代码。有没有办法只运行 pycurl 而不必在任何地方打印或写入结果?任何帮助将不胜感激。
p = pycurl.Curl()
p.setopt(pycurl.POST, 0)
p.setopt(pycurl.COOKIE, sessioncookie)
p.setopt(pycurl.URL, 'http://example.com/logoff.php')
p.perform()
p.close()
I am a beginner using Python and Pycurl for webpage stressing testing purposes. However, pycurl keeps printing out returned html in the terminal which makes the stress testing take even more time than it should. One such pycurl code I am using is posted below. Is there a way to just run pycurl without having to print or write the result anywhere? Any assistance would be appreiciated.
p = pycurl.Curl()
p.setopt(pycurl.POST, 0)
p.setopt(pycurl.COOKIE, sessioncookie)
p.setopt(pycurl.URL, 'http://example.com/logoff.php')
p.perform()
p.close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Pycurl 文档很糟糕,但我认为您想将 WRITEFUNCTION 设置为一个不执行任何操作的函数,例如
另外,我希望郑重声明,我认为“SET 可以做所有事情”API 随 VMS 一起推出。嘎啊。
The Pycurl documentation is terrible, but I think you want to set WRITEFUNCTION to a function that does nothing, e.g.
Also, I wish to state for the record that I thought "SET does everything" APIs went out with VMS. Gaaah.
可以试试这个吗?
或者只是一个什么都不做的函数。
Could try this?
or just a function that does nothing.
我对这里列出的两种方法都没有任何运气。两者都会导致以下错误:
根据文档,
lambda x: None
和devnull.write
应该是不错的选择:http://pycurl.sourceforge.net/doc/callbacks.html#WRITEFUNCTION
然而,在我的项目中,我必须执行以下操作来解决此问题:
换句话说,返回我查看时写入的字节数不是可选的。
devnull.write
实际上确实返回了写入的字节数,但我没有研究这一点。字节与字符串可能存在一些问题。请注意,我使用的是 Python 3。我猜这不适用于 Python 2。
I haven't had any luck with both approaches listed here. Both lead to the following error:
According to documentation both
lambda x: None
anddevnull.write
should be good options:http://pycurl.sourceforge.net/doc/callbacks.html#WRITEFUNCTION
However in my project I had to do the following to fix this problem:
In other words it was not optional to return the number of bytes written when I looked.
devnull.write
actually does return the number of bytes written, I didn't look into that though. Possibly there's some issue with bytes vs strings.Note that I'm using Python 3. I'm guessing this does not apply to Python 2.
要隐藏输出,请将 VERBOSE 更改为 0:
To hide the output, change the VERBOSE to 0: