• Python代码中执行curl命令查询couchbase数据


    最近在优化脚本时,发现要提前执行一段curl命令才行,实际在python中可以通过HTTP Library中requests方法就能实现,如

    要执行的curl命令为

    curl -v 'http://172.17.9.128:8091/pools/default/buckets/meta3/docs/8024028328' -u "XX:XX"
    

      

     在Python中直接对它进行请求就可以了

    查询接口

    def GetMetaData2(cb_url,uid):
        #"通过CB接口获取uid对应的离线消息表"
        
    
        meta = 'meta'
        bucket_num = uid%5
        bucket_name = meta + str(bucket_num)
        bucket_passwd = str(123)
        url = cb_url + bucket_name + "/docs" +'/'+ str(uid)
        password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
        password_mgr.add_password(None, url, user=bucket_name,passwd=bucket_passwd)
        handler = urllib.request.HTTPBasicAuthHandler(password_mgr)
        opener = urllib.request.build_opener(handler)
        urllib.request.install_opener(opener)
        f = urllib.request.urlopen(url)
        res = f.read()
        print("url:{0},response:{1}".format(url, res))
        return f.getcode(), res  

     得到的结果

    url:http://172.17.9.128:8091/pools/default/buckets/meta3/docs/8024028328,response:b'{"meta":{"id":"8024028328","rev":"4667-1677ce237da5000060812e5400000000","expiration":1619078740,"flags":0},"json":{"appkey":"c73fb613f8ef2a5c70396818","ttl":1619078740,"smsgs":{"num":5,"max_count":5,"58546795155930667":{"data_msgtype":2,"push_type":8,"is_vip":1,"ctime":1618988908,"ttl":1619075307,"stime":1618988908},"58546795155930668":{"data_msgtype":2,"push_type":8,"is_vip":1,"ctime":1618988911,"ttl":1619075311,"stime":1618989239},"58546795155930682":{"data_msgtype":2,"push_type":8,"is_vip":1,"ctime":1618988914,"ttl":1619075313,"stime":1618989240},"58546795155930672":{"data_msgtype":2,"push_type":8,"is_vip":1,"ctime":1618988915,"ttl":1619075315,"stime":1618989240},"58546795155930678":{"data_msgtype":2,"push_type":8,"is_vip":1,"ctime":1618988917,"ttl":1619075317,"stime":1618989240}}}}'
    

     删除接口使用delete就行

    def Delete_uid_metaall():
        resp = requests.delete("http://172.17.9.128:8091/pools/default/buckets/meta3/docs/8024028328", auth=HTTPBasicAuth('XXX', 'XXX'))
        print(resp)
    

      

     在查询就没有数据了

    作者:做梦的人(小姐姐)
    出处:https://www.cnblogs.com/chongyou/
    本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
    微信号:18582559217
  • 相关阅读:
    GDB常用命令
    codevs1743
    Codeforces Round #369 (Div. 2)E
    Codeforces Round #200 (Div. 2)E
    2016 Multi-University Training Contest 4 T9
    2016 Multi-University Training Contest 1 T3
    2016 Multi-University Training Contest 1 T4
    HDU 5448 Marisa’s Cake
    codeforces 467C George and Job dp
    poj 1704 Georgia and Bob 博弈
  • 原文地址:https://www.cnblogs.com/chongyou/p/14686045.html
Copyright © 2020-2023  润新知