Query string unescaped
Review this Python that builds a search URL from a user's raw query and fetches the upstream results.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 16 min
Mark a line and say what kind of problem it is.0 findings
1import requests
2
3BASE = 'https://api.example.com/search'
4
5def search_url(query, limit=20):
6 # query is raw user input, e.g. 'cats & dogs' or 'a=1&b=2'
7 return f'{BASE}?q={query}&limit={limit}'
8
9def search(query):
10 url = search_url(query)
11 resp = requests.get(url, timeout=5)
12 resp.raise_for_status()
13 return resp.json()['results']
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.