无法解码缓冲响应

时间:2018-04-13 12:42:53

标签: python python-3.x ubuntu ascii pycurl

我正在尝试使用pythonpycurl获取文本文件的内容。连接成功,我还设法用数据填充缓冲区,但当我尝试解码缓冲区时,我面临以下错误消息:

'ascii' codec can't encode characters in position 644-646: ordinal not in range(128)

以下是相关代码:

import pycurl
from io import BytesIO

def grabUrl(url):
  buffer = BytesIO()
  try:
    c = pycurl.Curl()
    c.setopt(c.WRITEDATA, buffer)
    c.setopt(pycurl.URL, url)
    c.perform()
    if c.getinfo(pycurl.RESPONSE_CODE) == 200:
      # Successful request so try to decode the response.
      content = buffer.getvalue().decode('iso-8859-1')
    c.close()
    # More code goes here.
  except Exception as e:
    print ("Exception: ", e)

我正在使用Python 3.4.3pyCurl 7.19.3Ubuntu 14.04

0 个答案:

没有答案