Bitcoin extracting cost of it

I am gettting the following error when i run the code to extract the current price of bitcoin
The code is:
import requests,json
def get_bitcoin_price():
URL = “https://min-api.cryptocompare.com/” # REPLACE WITH CORRECT URL
response = requests.request(“GET”, URL)
response = json.loads(response.text)
current_price = response[“USD”]
return current_price
print(get_bitcoin_price())

and output i get is:
Traceback (most recent call last):
File “C:/Users/Personal/AppData/Local/Programs/Python/Python37-32/bitcoin_proj.py”, line 8, in
print(get_bitcoin_price())
File “C:/Users/Personal/AppData/Local/Programs/Python/Python37-32/bitcoin_proj.py”, line 5, in get_bitcoin_price
response = json.loads(response.text)
File “C:\Users\Personal\AppData\Local\Programs\Python\Python37-32\lib\json_init_.py”, line 348, in loads
return _default_decoder.decode(s)
File “C:\Users\Personal\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\Users\Personal\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

1 Like

@sonusajid004 Please format your code. Based on what you have posted, it would seem that you have not formatted the code properly.

You can use the ``` before and after your code to format it.
For example,

from boltiot import Bolt
mybolt = Bolt("12345")

You need to pass the required cryptocurrency symbol and cryptocurrency symbols list to convert into in the url Check here https://min-api.cryptocompare.com/documentation

Also, check this code.

import requests, json

def get_bitcoin_price():
    URL = "https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD" # REPLACE WITH CORRECT URL
    response = requests.request("GET", URL)

    response = json.loads(response.text)

    print ("response is", response)
    current_price = response["USD"]
    return current_price



print (get_bitcoin_price())
3 Likes

iam getting key error.

Hi @konaabhishek1508,

Please share your code and screenshot of the error.

Yes,Its working.I corrected my code.Thank you @rahul.singh1 for responding.

Thank you for your help.the code worked :slightly_smiling_face:
@rahul.singh1

Hi. May I please know where you had to correct the code?