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'}
  • 相关阅读:
    物料外部编码的模糊查询
    ◆◆1LSMW的简单范例-LSMW导入会计科目
    通过Tcode查找LSMW
    LSMW批量更新物料主数据
    ◆◆0HR报表开发-Join & Projection
    HR常用宏(一)
    ◆◆0PM01-创建信息类型(infotype)教程
    keras_9_激活函数 Activations
    keras_8_优化器 Optimizers
    keras_7_评估标准 Metrics
  • 原文地址:https://www.cnblogs.com/duguxiren/p/11709076.html
Copyright © 2011-2022 走看看