python在向post数据时出现httplib.BadStatusLine: ''错误

发布于 2022-09-01 15:36:24 字数 2208 浏览 6 评论 0

源代码

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹿港巷口少年归 2022-09-08 15:36:24

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

明媚殇 2022-09-08 15:36:24

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文