我正在尝试使用python
和pycurl
获取文本文件的内容。连接成功,我还设法用数据填充缓冲区,但当我尝试解码缓冲区时,我面临以下错误消息:
'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.3
,pyCurl 7.19.3
和Ubuntu 14.04
。