当前位置: 首页>>代码示例>>Python>>正文


Python Request.headers['Content-Type']方法代码示例

本文整理汇总了Python中vcr.request.Request.headers['Content-Type']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.headers['Content-Type']方法的具体用法?Python Request.headers['Content-Type']怎么用?Python Request.headers['Content-Type']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vcr.request.Request的用法示例。


在下文中一共展示了Request.headers['Content-Type']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove_json_post_data_parameters

# 需要导入模块: from vcr.request import Request [as 别名]
# 或者: from vcr.request.Request import headers['Content-Type'] [as 别名]
def test_remove_json_post_data_parameters():
    body = b'{"id": "secret", "foo": "bar", "baz": "qux"}'
    request = Request('POST', 'http://google.com', body, {})
    request.headers['Content-Type'] = 'application/json'
    remove_post_data_parameters(request, ['id'])
    request_body_json = json.loads(request.body.decode('utf-8'))
    expected_json = json.loads(b'{"foo": "bar", "baz": "qux"}'.decode('utf-8'))
    assert request_body_json == expected_json
开发者ID:jayvdb,项目名称:vcrpy,代码行数:10,代码来源:test_filters.py

示例2: test_replace_json_post_data_parameters

# 需要导入模块: from vcr.request import Request [as 别名]
# 或者: from vcr.request.Request import headers['Content-Type'] [as 别名]
def test_replace_json_post_data_parameters():
    # This tests all of:
    #   1. keeping a parameter
    #   2. removing a parameter
    #   3. replacing a parameter
    #   4. replacing a parameter using a callable
    #   5. removing a parameter using a callable
    #   6. replacing a parameter that doesn't exist
    body = b'{"one": "keep", "two": "lose", "three": "change", "four": "shout", "five": "whisper"}'
    request = Request('POST', 'http://google.com', body, {})
    request.headers['Content-Type'] = 'application/json'
    replace_post_data_parameters(request, [
        ('two', None),
        ('three', 'tada'),
        ('four', lambda key, value, request: value.upper()),
        ('five', lambda key, value, request: None),
        ('six', 'doesntexist'),
    ])
    request_data = json.loads(request.body.decode('utf-8'))
    expected_data = json.loads('{"one": "keep", "three": "tada", "four": "SHOUT"}')
    assert request_data == expected_data
开发者ID:Bjwebb,项目名称:vcrpy,代码行数:23,代码来源:test_filters.py

示例3: test_remove_all_json_post_data_parameters

# 需要导入模块: from vcr.request import Request [as 别名]
# 或者: from vcr.request.Request import headers['Content-Type'] [as 别名]
def test_remove_all_json_post_data_parameters():
    body = b'{"id": "secret", "foo": "bar"}'
    request = Request('POST', 'http://google.com', body, {})
    request.headers['Content-Type'] = 'application/json'
    replace_post_data_parameters(request, [('id', None), ('foo', None)])
    assert request.body == b'{}'
开发者ID:Bjwebb,项目名称:vcrpy,代码行数:8,代码来源:test_filters.py

示例4: test_remove_nonexistent_json_post_data_parameters

# 需要导入模块: from vcr.request import Request [as 别名]
# 或者: from vcr.request.Request import headers['Content-Type'] [as 别名]
def test_remove_nonexistent_json_post_data_parameters():
    body = b'{}'
    request = Request('POST', 'http://google.com', body, {})
    request.headers['Content-Type'] = 'application/json'
    remove_post_data_parameters(request, ['id'])
    assert request.body == b'{}'
开发者ID:jayvdb,项目名称:vcrpy,代码行数:8,代码来源:test_filters.py


注:本文中的vcr.request.Request.headers['Content-Type']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。