zoukankan      html  css  js  c++  java
  • python 接口测试(二)

    1.响应转化为json字符串

    import requests
    import json
    re=requests.get('https://github.com/timeline.json')
    print(re.text)
    js=re.json()            #响应转化为json字符串
    print(js)
    # key_value=js['documentation_url']  #取键对应的值
    # print(key_value)

    响应:

    {"message":"Hello there, wayfaring stranger. If you’re reading this then you probably didn’t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.","documentation_url":"https://developer.github.com/v3/activity/events/#list-public-events"}
    {'message': 'Hello there, wayfaring stranger. If you’re reading this then you probably didn’t see our blog post a couple of years back announcing that this API would go away: http://git.io/17AROg Fear not, you should be able to get what you need from the shiny new Events API instead.', 'documentation_url': 'https://developer.github.com/v3/activity/events/#list-public-events'}

    2.序列化

    import requests
    import json  
    url = 'https://api.github.com/some/endpoint'
    payload={'some':'data','list':'[1,True]'}
    # print(type(payload))
    re=requests.post(url,data=json.dumps(payload))   #反序列化
    # re=requests.post(url,data=payload)
    print(re.text)
    print(re.json())

    响应;

    {"message":"Not Found","documentation_url":"https://developer.github.com/v3"}
    {'message': 'Not Found', 'documentation_url': 'https://developer.github.com/v3'}
  • 相关阅读:
    【杭电】[2035]人见人爱A^B
    【杭电】[2014]青年歌手大奖赛_评委会打分
    【杭电】[2014]青年歌手大奖赛_评委会打分
    【杭电】[2018]母牛的故事
    【杭电】[2018]母牛的故事
    SQL 01: 数据库表的三种关系
    History : The Age of the Samurai(11851868)
    History : Pictures of History 2
    JQuery 07 事件2
    JQuery 07 事件1
  • 原文地址:https://www.cnblogs.com/duguxiren/p/11709076.html
Copyright © 2011-2022 走看看