user1557515
user1557515

Reputation: 109

internal server error when trying to access my bitcoin core server via JSON-RPC

I am trying to access information from my bitcoin core server using JSON-RPC in python, but it returns this error:

 500 Server Error: Internal Server Error for url: http://username:password@127.0.0.1:8332/ 

it is not an issue with the username or password as this is setup in my bitcoin.config file as such:

server=1
rpcuser=username
rpcpassword=password
rpcport=8332
rpcallowip=127.0.0.1

here is my python code:

import requests
import json

# Bitcoin Core RPC settings
rpc_url = "http://username:password@127.0.0.1:8332/"
headers = {"Content-Type": "application/json"}

# Function to query Bitcoin Core via RPC
def rpc_call(method, params=None):
    data = {
        "jsonrpc": "1.0",
        "id": "python",
        "method": method,
        "params": params or []
    }
    try:
        response = requests.post(rpc_url, headers=headers, json=data)
        response.raise_for_status()  # Check for HTTP request errors
        return response.json()  # Parse the response JSON
        except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
        return None

any idea why I'm getting this error? thank you

Upvotes: -1

Views: 37

Answers (0)

Related Questions