0

The error message is as follows:

Traceback (most recent call last):
  File "./bitcoin_price.py", line 57, in <module>
    Coindesk()
  File "./bitcoin_price.py", line 45, in Coindesk
    coindesk.pass_for_request()
  File "./bitcoin_price.py", line 39, in pass_for_request
    get_price = BtcAPI(url, api_id, json_tree)
NameError: name 'url' is not defined

What am I missing, here? I'm guessing it is the coindesk.pass_for_request(), but I can't sort out exactly why the values don't get passed. Also, what is a good way to debug something like this? I'm having a rough time looking inside of the classes to see what is going on.

class Price:


    def __init__(self, api_id, url, json_tree):

        self.api_id = api_id
        self.url = url
        self.json_tree = json_tree

    def pass_for_request(self):

        get_price = BtcAPI(url, api_id, json_tree)
        get_price.btc_api_call()


def Coindesk():

    coindesk = Price(api_id ="coindesk", url = "https://api.coindesk.com/v1/bpi/currentprice.json", json_tree = "['time']['updated']")
    coindesk.pass_for_request()

2 Answers 2

1

There is no url or api_id variable in the scope of pass_for_request. You probably meant to access self.url and self.api_id, in python you have to use self. to access members unlike in other languages where using this. is optional.

Also another thing I spotted is when you're trying to create a Price in Coindesk you are passing in api_id and the other arguments as if they are arguments with defaults, which they are not. You'd need to call it as: Price("coindesk", "https://mylinktocoindesk", "['time']['updated']")

Here's some reading on OOP in python that you might find helpful: https://docs.python.org/3/tutorial/classes.html https://www.tutorialspoint.com/python/python_classes_objects.htm

Sign up to request clarification or add additional context in comments.

Comments

1

Try to replace

get_price = BtcAPI(url, api_id, json_tree)

with

get_price = BtcAPI(self.url, self.api_id, self.json_tree)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.