Python:使用 Solscan API 获取交易

Python: Use Solscan API to get transactions

我正在使用以下代码:

 import requests
 from requests.structures import CaseInsensitiveDict


 url='https://public-api.solscan.io/account/transactions?account=24jvtWN7qCf5GQ5MaE7V2R4SUgtRxND1w7hyvYa2PXG6'
 headers = CaseInsensitiveDict()
 headers["accept"] = "application/json"


 resp = requests.get(url, headers=headers)

 print(resp.json())

我得到一个错误:JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我希望得到 key:value 形式的输出,然后将其转换为 DataFrame。为什么会出现我的错误?

使用实际有效的headers

试试这个:

import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
}

url = 'https://public-api.solscan.io/account/transactions?account=24jvtWN7qCf5GQ5MaE7V2R4SUgtRxND1w7hyvYa2PXG6'
resp = requests.get(url, headers=headers)

print(resp.json()[0]['signer'])

示例输出:

['7BjLjdJEGLaLscYkpw57YKzYqRY1i3ypnfLK8R2bgDrC', '7qfzWZmyYU1PBYJG5Y2ksSbaf6xHc77Tx47urzySFins']