使用urlopen(IP).read()获取http.client.BadStatusLine

时间:2013-03-28 19:48:41

标签: python urllib strip python-3.3 urlopen

我试图读取的数据是xml格式。在xml声明之前有一个空格。我无法编辑此部分,因为它已硬编码到数据源中。我只能读它。当在IE中输入URL时,数据出现。在Chrome / Firefox中输入时,会显示错误,但可以从查看源查看数据。

是否有一种方法可以使用python来关闭此空间或忽略它,就像IE似乎一样?

(试图在很多地方添加strip())

或者有没有办法默认页面源(我想urlopen已经这样做了吗?)

以下是给出错误的行:

html = urlopen(address).read()

这是错误:

Traceback (most recent call last):
File "C:\Users\212311674\Desktop\Python Work\M10url.py", line 27, in <module>
  html = urlopen(address).read()
File "C:\Python33\lib\urllib\request.py", line 160, in urlopen
  return opener.open(url, data, timeout)
File "C:\Python33\lib\urllib\request.py", line 473, in open
  response = self._open(req, data)
File "C:\Python33\lib\urllib\request.py", line 491, in _open
  '_open', req)
File "C:\Python33\lib\urllib\request.py", line 451, in _call_chain
  result = func(*args)
File "C:\Python33\lib\urllib\request.py", line 1272, in http_open
  return self.do_open(http.client.HTTPConnection, req)
File "C:\Python33\lib\urllib\request.py", line 1257, in do_open
  r = h.getresponse()
File "C:\Python33\lib\http\client.py", line 1131, in getresponse
  response.begin()
File "C:\Python33\lib\http\client.py", line 354, in begin
  version, status, reason = self._read_status()
File "C:\Python33\lib\http\client.py", line 336, in _read_status
  raise BadStatusLine(line)
http.client.BadStatusLine:  <?xml version="1.0"?><controller_history_cnd>

先谢谢!

0 个答案:

没有答案