什么是下载比特币区块链数据最有效的方式?

2024-04-28 17:55:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经编写了一个脚本,可以获取输入比特币地址,并从blockchain.info下载包含两个输入地址的事务的所有块。区块总数:6013

问题是我经常会出现随机错误。我得到的最新错误:

requests.exceptions.ConnectionError:('Connection aborted.',RemoteDisconnected('Remote end closed Connection without response',))

我在崩溃前存储了适当的变量值,以便下次可以从那里开始

Idk,如果它是相关的,但我曾经得到了500个状态码很多。因此,每次发送500状态码时,我都会将计时器设置为20“,然后再尝试连接到服务器

我将提供连接的代码

    for line in tmp:
        words = line.split(",")
        s = words[2]
        s2 = words[1]
        print("Block Index: ", s, "Block Height: ", s2)

        with requests.Session() as keep_alive:
            url = "https://blockchain.info/rawblock/" + str(s)

            response = keep_alive.get(url, stream = True)
            if response.status_code == 200:
                print("Status code: ", response.status_code)

            increase = 0
            sc = response.status_code #status code
            while sc == 500 or sc == 104:
                print("Status code: ", response.status_code)
                print("Server side message: ", response.text)
                response.close()
                t = 20
                while t:
                    mins, secs = divmod(t, 60)
                    timeformat = '{:02d}:{:02d}'.format(mins, secs)
                    print(timeformat, end='\r')
                    time.sleep(1)
                    t -= 1
                response = keep_alive.get(url, stream = True)
                print("Status code: ", response.status_code)

        data = response.json()

在这一点上,我不知道


Tags: infourlresponse地址status错误coderequests