• Mosquitto 创建用户自动输入密码


    1,Mosquitto默认是匿名用户登录,修改成用户登录模式需要修改文件/etc/mosquitto/mosquitto.conf

          添加如下:      

          allow_anonymous false
          password_file /etc/mosquitto/pwfile  //可以指定自己的文件

    2, 添加用户

          mosquitto_passwd -c /etc/mosquitto/pwfile xtest   //添加用户xtest  ,存在有其他用户的情况下,不用-c ,-c 会把其他用户的信息清除掉。

          

    3,查看

          cat /etc/mosquitto/pwfile

          

          生成了用户xtest

    4,我的项目中需要在django中自动生成用户。如何解决2中描述的手动输入密码的方式。

          python 中提供了一个pexcept 工具可以解决这个问题。pip install pexcept 完成安装。

          实现代码如下:      

    import pexpect
    sub = pexpect.spawn('mosquitto_passwd /etc/mosquitto/pwfile %s'%‘testtest’)
    sub.expect('Password:')//模拟第一次密码输入
    sub.sendline('12345678')
    sub.expect('Reenter password:')//模拟第二次密码输入
    sub.sendline('12345678')

    sub.interact()
  • 相关阅读:
    前端开发经验总结
    开发组件的原则
    jQuery deferred对象API详解
    prototype、constructor那点事儿
    text-overflow:ellipsis的那点事儿
    9 个超实用的 jQuery 代码片段
    BFC
    Console命令详解,让调试js代码变得更简单
    前端css规范
    什么是FOUC?如何避免FOUC?
  • 原文地址:https://www.cnblogs.com/huanhuaqingfeng/p/11283191.html
Copyright © 2020-2023  润新知