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

一、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)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容