【问题标题】:Parse POST HTTP response using Python使用 Python 解析 POST HTTP 响应
【发布时间】:2016-06-28 12:11:38
【问题描述】:

我想使用 python 解析一个 POST HTTP 响应。

我的回复如下:

{
  "Result": 0,
  "ResponseStatus": {
    "ErrorCode": null,
    "Message": null,
    "StackTrace": null,
    "Errors": null
  },
  "SessionId": "68ebcd6f-0aef-420d-a12b-c953f8df8ed1",
  "ResponseHeader": {
    "Succeeded": true,
    "Errors": []
  }
}

我想将“SessionID”解析为第二个 http 请求。 我怎样才能实现它?谢谢 !

【问题讨论】:

  • 使用json模块。
  • 请添加您用来检索该代码的代码,以便我们根据它提供帮助。谢谢!

标签: python parsing httprequest httpresponse


【解决方案1】:
import json 
response = '{"Result": 0, "ResponseStatus": { "ErrorCode": null,"Message": null, "StackTrace": null, "Errors": null },"SessionId": "68ebcd6f-0aef-420d-a12b-c953f8df8ed1", "ResponseHeader": { "Succeeded": true, "Errors": [] } }'
json_response = json.loads(response)
print json_response['SessionId']

我猜你使用的是 urllib,我推荐使用requests

【讨论】:

  • 谢谢!我是 python 新手。如果你能帮我写 2 个 http 请求,我将不胜感激,第二个请求是基于第一个请求中的 SessionId
猜你喜欢
  • 1970-01-01
  • 2014-05-27
  • 1970-01-01
  • 2014-09-03
  • 1970-01-01
  • 1970-01-01
  • 2018-01-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多