Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can someone help me with this error that im getting?

I’m trying to make a crypto command but its giving me an error.I tried doing everything i can’t seem to fix it. If anyone fixes it please mention how you fixed it i need to learn how cause i get these errors very frequently.
This is the code:

@client.command(pass_context=True)
async def ethprice(ctx):
    response = requests.get('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD')
    json_data = json.loads(response.text)
    price = json_data['USD']
  await ctx.send("Etherium price is: $" + price)

TypeError: can only concatenate str (not "float") to str

If anyone can help me i’d appriciate it 🙂

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your price variable is a float. You simply need to convert it to a string before using the + operator.

@client.command(pass_context=True)
async def ethprice(ctx):
    response = requests.get('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD')
    json_data = json.loads(response.text)
    price = json_data['USD']
  await ctx.send("Etherium price is: $" + str(price))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading