0

I have a problem with the etherscan api on ropsten testnetwork, the output of the code is: expecting value line 1 column 1 (char 0)

the code:

import requests, json

ADD = "0xfbb61B8b98a59FbC4bD79C23212AddbEFaEB289f"
KEY = "HERE THE API KEY"


REQ = requests.get(f"https://api-ropsten.etherscan.io/api?module=account&action=balance&address={str(ADD)}&tag=latest&apikey={str(KEY)}")

CONTENT = json.loads(REQ.content)
BALANCE = int(CONTENT['result'])

print(BALANCE)

When I try to do a request it gives back <Response [403]>

TylerH
  • 20,799
  • 66
  • 75
  • 101
Arthur
  • 26
  • 9

1 Answers1

0

Some websites don't allow Python scripts to access their website. You can get around this by adding a user agent in you request.

the code would look something like this:

import requests, json

ADD = "0xfbb61B8b98a59FbC4bD79C23212AddbEFaEB289f"
KEY = "HERE THE API KEY"
LINK = f"https://api-ropsten.etherscan.io/api?module=account&action=balance&address={str(ADD)}&tag=latest&apikey={str(KEY)}"
headers = {"HERE YOUR USER-AGENT"}

REQ = requests.get(LINK, headers = headers)

CONTENT = json.loads(REQ.content)
BALANCE = int(CONTENT['result'])

print(BALANCE)

To find your user agent simply type in google: my user agent

TylerH
  • 20,799
  • 66
  • 75
  • 101
Arthur
  • 26
  • 9