Pycurl and io.StringIO - pycurl.error: (23, 'Failed writing body)

Deadly 提交于 2019-12-02 23:35:25

I believe the problem is that pycurl no longer functions with StringIO like desired. A solution is to use io.BytesIO instead. You can then get information written into the buffer and decode it into a string.

Using BytesIO with pycurl instead of StringIO:

e = io.BytesIO()
c.setopt(pycurl.WRITEFUNCTION, e.write)

Decoding byte information from the BytesIO object:

htmlString = e.getvalue().decode('UTF-8')

You can use any type of decoding you want, but this should give you a string object you can parse.

Hope this helps people using Python 3.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!