python在向post数据时出现httplib.BadStatusLine: ''错误
源代码
import urllib
import urllib2
url = '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/ledongli
Traceback (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
哪位大神帮忙看下
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
先把
'Content-Length': '489'
去掉再看楼上的建议我的问题解决了, 点个赞