【问题标题】:Invalid data format returned from httplib.HTTPSConnection requesthttplib.HTTPSConnection 请求返回的数据格式无效
【发布时间】:2014-10-08 18:50:45
【问题描述】:
#!/usr/local/bin/python2.7

import httplib, urllib

params = urllib.urlencode({"username":"api", "password":"cisco123", "data":{"token":""}})
headers = {"Content-Type":"application/json", "Accept":"application/json"}

conn = httplib.HTTPSConnection("10.86.79.93", 443)
conn.request("GET", "/restapi/16/authenticate", params, headers)

response = conn.getresponse()

print "\n"

print response.status, response.reason

data = response.read()

print "\n"

print data

print "\n"

print response.msg

print "\n”

Output:

The response data is looking for JSON and here is the example they give:


“data”:{“token”:”1234567890xxxxxxxxxxxxxxxxxxxxx”}

200 OK


{"status":100,"message":"Invalid data format.","data":null,"envelope_version":"16"}
  • 日期:2014 年 8 月 15 日星期五 00:10:49 GMT

  • 服务器:Apache/2.2.15 (CentOS)

  • X-Powered-By:PHP/5.4.14

  • 内容长度:83

  • 连接:关闭

  • 内容类型:文本/html; charset=UTF-8

知道为什么我会在数据响应中收到“无效数据格式”消息和空值吗?

【问题讨论】:

    标签: python json api response httplib


    【解决方案1】:

    我相信 urllib.urlencode 不能很好地处理嵌套的 json。您在“数据”:{“令牌”:“”}中有一个嵌套对象。看urlencode a multidimensional dictionary in python 寻求解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      相关资源
      最近更新 更多