Home > front end >  Python: Use Solscan API to get transactions
Python: Use Solscan API to get transactions

Time:04-28

I am using the following code:

 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())

I get an error: JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I expect to get an output with in the form of key:value and then covnvert that to a DataFrame. Why does my error occur?

CodePudding user response:

Use headers that actually work.

Try this:

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'])

Sample output:

['7BjLjdJEGLaLscYkpw57YKzYqRY1i3ypnfLK8R2bgDrC', '7qfzWZmyYU1PBYJG5Y2ksSbaf6xHc77Tx47urzySFins']
  • Related