zoukankan      html  css  js  c++  java
  • Python接口测试之cookies传值

    在做接口自动化时,大家应该都会遇到后续接口需要cookies,否则请求报错,废话不多说,直接贴码

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    import urllib2
    import urllib
    import cookielib
    #获取cookies对象
    cookiejar=cookielib.CookieJar();
    #自定义urlOpener,并将其与Cookies对象绑定
    urlOpener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
    headers={"User-agent":"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1"};
    data={'username':'wu.xiaohong','password':'123456'};
    postdata = urllib.urlencode(data);
    url_1='http://IP:端口/login';
    request=urllib2.Request(url_1,postdata,headers);
    url=urlOpener.open(request);
    url_2='http://IP:端口/api/repayment/queryAmount?bid=1351793&period=3&prapay=false'
    request=urllib2.Request(url_2)
    url= urlOpener.open(request)
    page=url.read()
    print page
  • 相关阅读:
    Game Engine Architecture 3
    Game Engine Architecture 2
    补码
    工厂模式
    Game Engine Architecture 1
    YDWE Keynote
    3D Math Keynote 4
    3D Math Keynote 3
    3D Math Keynote 2
    OGRE中Any 类型的实现
  • 原文地址:https://www.cnblogs.com/hlweng/p/7463401.html
Copyright © 2011-2022 走看看