1

我是编程新手,我正在尝试访问http://indicadoreseconomicos.bccr.fi.cr/indicadoreseconomicos/WebServices/wsindicadoreseconomicos.asmx?op=ObtenerIndicadoresEconomicosXML中提供的网络服务,我已经添加了我需要的参数访问它,但是当我尝试在 python 中读取文件时,我得到 TypeError:'HTTPResponse' 对象不能被解释为整数

这是我的代码

import urllib
import http.client
import time
HEADERS={"Content-type":"application/x-www-form-urlencoded","Accept":"text/plain"}
HOST = "indicadoreseconomicos.bccr.fi.cr"
POST = "/indicadoreseconomicos/WebServices/wsIndicadoresEconomicos.asmx/ObtenerIndicadoresEconomicos"
data = urllib.parse.urlencode({'tcIndicador': 317,
                           'tcFechaInicio':str(time.strftime("%d/%m/%Y")),
                           'tcFechaFinal':str(time.strftime("%d/%m/%Y")),
                           'tcNombre' : 'TI1400',
                           'tnSubNiveles' : 'N'})
conn=http.client.HTTPConnection(HOST)
conn.request("POST",POST,data,headers=HEADERS)
response= conn.getresponse()
responseSTR= response.read(response)
print (response)

任何建议都值得赞赏

4

1 回答 1

0

response.read() takes an optional argument that is the number of bytes to read from the response; an integer, whole number. Now you passed the response object instead.

As you want to read the entire response, you should omit the argument altogether, thus:

response_str = response.read()
print(response_str)
于 2015-03-25T22:08:46.190 回答