Python之通过url抓取pickle文件

代码展示

# -*- coding:utf-8 -*-
import pickle as pk
import urllib.request


def fetchPickleFileFromHttp(pickle_file_url, timeout_s=1):
    try:
        if pickle_file_url:
            data = urllib.request.urlopen(pickle_file_url, timeout=timeout_s)
            return pk.load(data)
        else:
            return []
    except Exception as error:
        print('获取图片失败', error)
        return []


ng_info_url = 'http://192.168.18.114/WX130DA/ng_img/20210104113531/ng_info.pk'

data = fetchPickleFileFromHttp(ng_info_url)
print(data)

 

你可能感兴趣的:(python)