Some questions about the flask application of python

in the process of learning flask, I encounter a strange problem. Maybe I am not good at learning skills. I hope the master will correct me

.
-sharp 
class ShuBook:
    isbn_url = "http://t.yushu.im/v2/book/isbn/{}"
    keyword_url = "http://t.yushu.im/v2/book/search?q={}&count={}&start={}"

    @classmethod
    def search_by_isbn(cls,isbn):
        url = cls.isbn_url.format(isbn)
        print(locals())
        result = HTTP.get(url)   -sharp resultdict json 
        print(locals())   -sharp------------------------
        return result

    @classmethod
    def search_by_keyword(cls,keyword,count=15,start=0):
        url = cls.keyword_url.format(keyword,count,start)
        result = HTTP.get(url)
        return result
-sharp HTTP
import requests

class HTTP:
    @staticmethod
    def get(self, url, return_json = True):
        r = requests.get(url)
        -sharp restful API
        -sharp json
        if r.status_code != 200:
            return {} if return_json else ""
        return r.json() if return_json else r.text   

Program prompt error
get () missing 1 required positional argument: "url"
what is the reason why I should automatically apply the default parameter return_json = True, if I don"t set the second parameter here?
Thank you for correcting

Jul.22,2021

says that there are fewer url parameters, not less return_json.
did you enter url when you called get ()?


the functions in your HTTP class use the decorator of static functions, so the parameter in your get () function has a self, that you need to enter yourself. If you call url, alone, the procedure to be called is get (self=url, url, return_json = True), so it will report an error, missing url assignment


)

the get method in the HTTP class is static and does not require the self parameter

class HTTP:
    @staticmethod
    def get(url, return_json = True):  -sharp self
        r = requests.get(url)
        -sharp restful API
        -sharp json
        if r.status_code != 200:
            return {} if return_json else ''
        return r.json() if return_json else r.text   

def search_by_isbn(cls,isbn):
        url = cls.isbn_url.format(isbn)
        print(locals())
        result = HTTP.get(url)   
        print(locals())  
        return result   -sharp dictjson

after tossing through the questions for several days, I was still defeated on a weak foundation. Thank you for your patient answers. Thank you for your patient answers. Thank you
for synthesizing the conclusions of the previous experts. I found my own problems, so I should vote for myself. So as not to offend others

Menu