Python post数据遇到httplib.BadStatusLine: ''问题求解,,源代码import ur


源代码

import urllibimport urllib2url = 'http://pl.api.ledongli.cn/xq/io.ashx'values = {'action':'profile',          'pc':'andfa53e833c2f10a04456ecbb05789ca6',          'cmd':'updatedaily',           'uid':'29833686',          'list':[{"distance":233.65168,"duration":120.057373046875,"report":"[{\"calories\":0,\"distance\":0,\"duration\":120.057373046875,\"steps\":0,\"activity\":\"walking\"}]","calories":10.274937086736001,"steps":837,"pm2d5":0,"date":1437494400,"activeValue":7995}]}data = urllib.urlencode(values)header={'If-Modified-Since': 'Tue, 21 Jul 2015 23:58:52 GMT+00:00',         'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',          'User-Agent': 'Dalvik/1.6.0 (Linux; U; Android 4.4.4; HM NOTE 1S MIUI/V6.6.1.0.KHKCNCF)',          'Host': 'pl.api.ledongli.cn',          'Connection':'Keep-Alive',          'Accept-Encoding': 'gzip',          'Content-Length': '489'}req = urllib2.Request(url, data,headers=header)response = urllib2.urlopen(req)the_page = response.read()print the_page

报错

C:\Python27\python.exe E:/python/ledongliTraceback (most recent call last):  File "E:/python/ledongli", line 18, in <module>    response = urllib2.urlopen(req)  File "C:\Python27\lib\urllib2.py", line 127, in urlopen    return _opener.open(url, data, timeout)  File "C:\Python27\lib\urllib2.py", line 404, in open    response = self._open(req, data)  File "C:\Python27\lib\urllib2.py", line 422, in _open    '_open', req)  File "C:\Python27\lib\urllib2.py", line 382, in _call_chain    result = func(*args)  File "C:\Python27\lib\urllib2.py", line 1214, in http_open    return self.do_open(httplib.HTTPConnection, req)  File "C:\Python27\lib\urllib2.py", line 1187, in do_open    r = h.getresponse(buffering=True)  File "C:\Python27\lib\httplib.py", line 1045, in getresponse    response.begin()  File "C:\Python27\lib\httplib.py", line 409, in begin    version, status, reason = self._read_status()  File "C:\Python27\lib\httplib.py", line 373, in _read_status    raise BadStatusLine(line)httplib.BadStatusLine: ''Process finished with exit code 1

哪位大神帮忙看下

楼上的建议我的问题解决了, 点个赞

先把'Content-Length': '489' 去掉再看

编橙之家文章,

评论关闭