找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3658|回复: 1

[已解决] httplib2请求,返回400错误

1

主题

1

帖子

1

积分

贫民

积分
1
金色闪光 发表于 2016-8-30 16:43:52 | 显示全部楼层 |阅读模式
# -*- coding: UTF-8 -*-
import httplib2
import json
from urllib.parse import  urlencode
httplib2.debuglevel=1
url="http://test.haigeek.com:9030/selfservice/haigeek/index/login"
data=str({"username":"zhangjixuan@haierubic.com","password":"123123"})
headera={"Accept-Language": "zh-CN,zh;q=0.8","appVersion": "10.01.1100025", "Accept": "application/json,text/plain, */*", "Host": "test.haigeek.com:9030", "DNT": "1", "Connection": "keep-alive", "accessToken": "32232", "Accept-Encoding": "gzip, deflate", "appKey": "bf0dacd18e5abc73a452374b9ce3287d", "sequenceid": "1472122188242", "clientid": "1", "appId": "MB-DEVELOPERSITE-0000", "Cache-Control": "no-cache"}
httpObject=httplib2.Http()
resp, content = httpObject.request(url,method="POST",body=data,headers=headera)
print("\n\n\n---------------------------\n\n\n")
print(resp)
print(content)
send: b'POST /selfservice/haigeek/index/login HTTP/1.1\r\nContent-Length: 63\r\nappversion: 10.01.1100025\r\nconnection: keep-alive\r\nsequenceid: 1472122188242\r\naccept-encoding: gzip, deflate\r\naccept: application/json,text/plain, */*\r\naccesstoken: 32232\r\ndnt: 1\r\nappid: MB-DEVELOPERSITE-0000\r\nhost: test.haigeek.com:9030\r\naccept-language: zh-CN,zh;q=0.8\r\nuser-agent: Python-httplib2/0.9.2 (gzip)\r\nclientid: 1\r\ncache-control: no-cache\r\nappkey: bf0dacd18e5abc73a452374b9ce3287d\r\n\r\n'send: b"{'username': 'zhangjixuan@haierubic.com', 'password': '123123'}"reply: 'HTTP/1.1 400 Bad Request\r\n'header: Server header: Date header: Content-Type header: Transfer-Encoding header: Connection header: Pragma header: Expires header: Cache-Control header: Cache-Control header: Set-Cookie ---------------------------{'transfer-encoding': 'chunked', 'expires': 'Thu, 01 Jan 1970 00:00:00 GMT', 'connection': 'keep-alive', 'content-type': 'application/json;charset=UTF-8', 'date': 'Tue, 30 Aug 2016 08:23:35 GMT', 'server': 'nginx/1.10.1', 'cache-control': 'no-cache, no-store', 'set-cookie': 'JSESSIONID=25DC096708771DC17F394E7763CDCB8C; Path=/selfservice/; HttpOnly', 'status': '400', 'pragma': 'no-cache'}b'{"retCode":"400","retInfo":"Syntax error","description":"The request sent by the client was syntactically incorrect."}\r\n'

从网上搜索了些帖子,赶紧和网上请求格式对着呀,只能求教下各位大神了

回复

使用道具 举报

50

主题

1057

帖子

1108

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1108

活跃会员热心会员最佳导师默默耕耘突出贡献优秀版主荣誉管理论坛元老

blueelwang 发表于 2016-8-30 17:51:47 | 显示全部楼层
data=str({"username":"zhangjixuan@haierubic.com","password":"123123"}) 这里不对吧
应该是个字符串, 但是不是使用str转换, 而是使用urlencode进行转换
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表