玩蛇网提供最新Python编程技术信息以及Python资源下载!
您现在的位置: 玩蛇网首页 > Python问题解答 > 正文内容

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

哪位大神帮忙看下

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

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

玩蛇网文章,转载请注明出处和文章网址:http://www.iplaypy.com/wenda/wd18453.html

相关文章 Recommend

玩蛇网Python互助QQ群,欢迎加入-->: 106381465 玩蛇网Python新手群
修订日期:2017年06月15日 - 09时34分49秒 发布自玩蛇网

我要分享到:

必知PYTHON教程 Must Know PYTHON Tutorials

必知PYTHON模块 Must Know PYTHON Modules