Pycurl WRITEDATA WRITEFUNCTION 碰撞/崩溃

发布于 2024-07-09 04:25:50 字数 573 浏览 9 评论 0原文

如何关闭 WRITEFUNCTION 和 WRITEDATA?

使用 pycurl 我有一个名为curlUtil 的类。 其中我有 pageAsString (self, URL) 返回一个字符串。

为此,我设置了 WRITEFUNCTION。 现在在 downloadFile (self, URL, fn, overwrite=0) 中,我做了一个 open 和 self.c.Setopt (pycurl.WRITEFUNCTION, 0) ,这会导致问题。 Int 不是有效的参数。

然后我假设 WRITEDATA 会覆盖该值,或者会有一个 NOWRITEFUNCTION 推荐。 NOWRITEFUNCTION 不存在,所以我只使用 WRITEDATA 并且 Python 崩溃了。

我编写了一个名为reboot()的快速函数,它关闭curl,再次打开它,并调用reset将其置于默认状态。 我在pageAsString和downloadFile中都调用它,完全没有问题。 但是,我不想重新初始化卷曲。 我可能设置了一些特殊选项。

如何关闭 WRITEFUNCTION 和 WRITEDATA?

How do I turnoff WRITEFUNCTION and WRITEDATA?

Using pycurl I have a class call curlUtil. In it I have pageAsString (self, URL) which returns a string.

To do this I setopt WRITEFUNCTION. Now in downloadFile (self, URL, fn, overwrite=0) I do an open and self.c.Setopt (pycurl.WRITEFUNCTION, 0) which cause problems. Int is not a valid argument.

I then assumed WRITEDATA would overwrite the value or there would be a NOWRITEFUNCTION commend. NOWRITEFUNCTION didn't exist so I just used WRITEDATA and Python crashed.

I wrote a quick func called reboot() which closes curl, opens it again, and calls reset to put it in the default state. I call it in both pageAsString and downloadFile and there is no problem at all. But, I don't want to reinitialize curl. There might be some special options I set.

How do I turnoff WRITEFUNCTION and WRITEDATA?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您的好友蓝忘机已上羡 2024-07-16 04:25:50

使用 write 函数,而不是关闭它会为你省去很多麻烦。 来重写 pageAsString :

您可能想使用 WRITEFUNCTION..作为示例

from cStringIO import StringIO
c = pycurl.Curl()
buffer = StringIO()
c.setopt(pycurl.WRITEFUNCTION, buffer.write)
c.setopt(pycurl.URL, "http://example.com")
c.perform()
...
buffer.getvalue() # will return the data fetched.

using the writefunction, instead of turning it off would save you a lot off trouble. you might want to rewrite your pageAsString by utilizing WRITEFUNCTION..

as an example:

from cStringIO import StringIO
c = pycurl.Curl()
buffer = StringIO()
c.setopt(pycurl.WRITEFUNCTION, buffer.write)
c.setopt(pycurl.URL, "http://example.com")
c.perform()
...
buffer.getvalue() # will return the data fetched.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文