3

Here is the function I made:

@app.get("/shows/")
def get_items(q: List[str] = Query(None)):
    '''
    Pass path to function.
    Returns folders and files.
    '''
    results = {}

    query_items = {"q": q}
    if query_items["q"]:
        entry = PATH + "/".join(query_items["q"])
    else:
        entry = PATH

    if os.path.isfile(entry):
        return download(entry)

    dirs = os.listdir(entry + "/")
    results["folders"] = [
        val for val in dirs if os.path.isdir(entry + "/" + val)]
    results["files"] = [val for val in dirs if
                        os.path.isfile(entry + "/" + val)]
    results["path_vars"] = query_items["q"]

    return results

Idea is to pass an array of string which essentially form a path in the function to a file and I can have some array to it from an app to serve files and send this function an array of string as they traverse the folders. But.. I cant figure out how to send a list of params from something like python requests.

Here is a sample function I wrote.

def try_url():
    url = "http://192.168.0.16:8000/shows/"

    payload = {
        "q": ["downloads",
              "showname"]
    }
    headers = {}

    response = requests.request("GET", url, headers=headers, data=payload)

    print(response.text.encode('utf8'))

Api doesnt even accept a q value. What am I missing? Is this the right way to traverse dirs? In url format, this is what a request looks like:

http://192.168.0.16:8000/shows/?q=downloads&q=foldername

Doesnt look right to me.

1 Answer 1

4

I am dumb, the solution was simply to pass params to the call ...

payload = {
    "q" : ["downloads",
    "Brooklyn.Nine-Nine.S07E01.720p.HEVC.x265-MeGusta"]
}
headers = {
}

response = requests.request("GET", url, headers=headers, params = payload)

adding "params" in requests.request is the solution.

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

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.