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'}
  • 相关阅读:
    tmux commands
    智能指针类HasPtr
    关于Vector中存放指针的问题
    面向对象的理解
    关系模型 超键 候选键 主键
    数据库的三个范式
    static struct QMetaObject const QwtPlot::staticMetaObjec
    static作用(修饰函数、局部变量、全局变量)
    C++全局变量之extern和static
    QTabWidget 使用小记
  • 原文地址:https://www.cnblogs.com/duguxiren/p/11709076.html
Copyright © 2011-2022 走看看