美文网首页
python发送http json请求

python发送http json请求

作者: timar | 来源:发表于2019-11-06 16:30 被阅读0次

    公司有个自动化测试平台,用monaco-editor写python脚本然后执行

    import json
    import urllib.request
    import urllib.parse
    
    request={
                "phone": "",
                "cardNoList": [
                    {
                        "cardNoType": "01",
                        "cardNo": "6222021202021314788",
                        "customerID": "111111111",
                        "mobileNo": "",
                        "defaultCardFlag": "",
                        "bankName": "",
                        "acctBranch": "",
                        "accountLevel": ""
                    }
                ]
            }
    
    aheaders = {'Content-Type': 'application/json'}
    baseurl = 'http://55.11.24.87:8080/query'
    postdata = urllib.parse.urlencode(self.request).encode('utf-8')
    req = urllib.request.Request(url=baseurl, headers=aheaders, data=json.dumps(self.request).encode('utf-8'))
    rsp = urllib.request.urlopen(req)
    response = json.loads(rsp.read().decode())
            
    self.response = response
    print("111111111111")
            
    # assert 2 == 3, self.response
    

    assert 2==3, self.response是为了显示返回信息,因为print打印不出来

    相关文章

      网友评论

          本文标题:python发送http json请求

          本文链接:https://www.haomeiwen.com/subject/benubctx.html