-1

I am trying to make a post request to this website: https://www.myetherapi.com/. I'm not sure what is wrong with my request, but print(res) returns <Response [403]> and print(res.json()) returns the error:

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Code:

import requests
import json


url = 'https://api.myetherapi.com/eth'
headers = {'content-type': 'application/json'}

payload = {
    "jsonrpc": "2.0",
    "method": "eth_getBalance",
    "params": ["0x7cB57B5A97eAbe94205C07890BE4c1aD31E486A8", "latest"],
    "id": 1
    }

res = requests.post(url, data=json.dumps(payload), headers=headers)


print(res)
print(res.json())

Any idea on what I am doing wrong?

Edit:

I had posted this question and then turned off my computer. when I returned a few hours later and read the answers on this thread, i ran the code again and it worked. Then a few minutes later it's not working again. All i did is browse some web pages between the time it worked and stopped working. I am running this in pycharm. How i am running it

zonzon510
  • 163
  • 13

2 Answers2

0

Have you tried it several times? You should also check res.text, maybe there is some error response related to your issue.

Maybe you should try a proxy? http://docs.python-requests.org/en/master/user/advanced/#proxies

The code above works and returns this:

>>> res.json()
{'jsonrpc': '2.0', 'result': '0x4017bc319327a00', 'id': 1}
d2718nis
  • 1,279
  • 9
  • 13
-1

The HTTP 403 Forbidden from wiki:

HTTP 403 is an HTTP status code that indicates that the server that the client is attempting to communicate with understood the request, but will not fulfill it for a reason other than authorization.

Error 403: "The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated."

Maybe the server avoid being spam. (or your internet is having problem) In some case, it was because of lacking the User-Agent. It might help. You can check this question. Python requests. 403 Forbidden

Community
  • 1
  • 1
NLag
  • 75
  • 6