如何使用 python3 通过 rpc 连接到比特币核心?

how to connect to bitcoin core over rpc with python3?

与 python3,我找到了这个例子,但我得到了“错误 405”

script.py

import json
import requests

rpcPort = 9337
rpcUser = 'rpcuser'
rpcPassword = 'rpcpassword'
rpcIp = '127.0.0.1'

serverURL = 'http://' + str(rpcUser) + ':' + str(rpcPassword)+ '@' + str(rpcIp)+":" + str(rpcPort)

headers = {'content-type: text/plain'}
#payload = json.dumps({"method": 'getblockhash', "params": ["0"], "jsonrpc": "2.0"})
payload = json.dumps({"method": 'getblock', "params": ["0000000000005e5fd51f764d230441092f1b69d1a1eeab334c5bb32412e8dc51"]})
response = requests.get(serverURL, headers=headers, data=payload)
print(response)
#print(response.json()['result'])

bitcoin.conf

server=1
txindex=1
whitelist=0.0.0.0
rpcallowip=0.0.0.0/0
rpcconnect=127.0.0.1
rpcbind=127.0.0.1
rpcport =9337
rpcuser=rpcuser    
rpcpassword=rpcpassword


test-rpc.py
<Response [405]>

我不知道我对这个 405 做错了什么

从这里的这个问题:bitcoin json rpc with python requests module?,看起来你应该使用 POST 发送请求。

response = requests.post(serverURL, headers=headers, data=payload)