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

后端 未结 1 1917
自闭症患者
自闭症患者 2021-02-01 23:21

I\'m porting ebay sdk to python3 and I\'ve stumbled upon the following issue.

I\'m using pycurl to send some HTTP requests. Here is how I configure it:

          


        
相关标签:
1条回答
  • 2021-02-01 23:55

    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.

    0 讨论(0)
提交回复
热议问题