美文网首页
项目问题总结(2018-10-09)

项目问题总结(2018-10-09)

作者: sunshaoping | 来源:发表于2018-10-09 13:50 被阅读0次

    一、python获取json数据

    import urllib.request
    
    
    def get_exchange_list():
        exchanges_list = json.loads(urllib.request.urlopen('http://q.botvs.net/api/symbols').read())
        return exchanges_list
    
    

    报错:TypeError: the JSON object must be str, not 'bytes',意思为json对象必须为字符串类型,而不是字节类型

    def get_exchange_list():
        exchanges_list = json.loads(urllib.request.urlopen('http://q.botvs.net/api/symbols').read().decode("utf-8"))
        return exchanges_list
    

    问题解决

    二、python ping ip

    import os,datetime,time
    
    def run():
        ip1 = "www.baidu.com"
        backinfo = os.system("ping -w 1 %s" % ip1)
        if backinfo != 0: 
            with open("app.txt", "a") as f:
                f.write(str(datetime.datetime.now()) + "--" + str(ip1) + "--" + str(backinfo) + "\n")
                f.close()
    
    
    if __name__ == '__main__':
        while True:
            run()
            time.sleep(60)
    

    相关文章

      网友评论

          本文标题:项目问题总结(2018-10-09)

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