Skip to content

Commit

Permalink
Fix JSONDecodeError on sent request with no Category selected
Browse files Browse the repository at this point in the history
error: json.decoder.JSONDecodeError
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

* Also add blacklist flag to url only if selected any

Signed-off-by: Hemant Sachdeva <hemant.evolver@gmail.com>
  • Loading branch information
HemantSachdeva committed Oct 20, 2021
1 parent 827a3fc commit 8ab814b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@
def index():
if request.method == 'POST':
cat = request.form.getlist('catagory')
cat = ','.join(cat) # making cat list a ',' separated string
if cat:
cat = ','.join(cat) # making cat list a ',' separated string
url = "https://v2.jokeapi.dev/joke/{}".format(cat)
else:
url = "https://v2.jokeapi.dev/joke/Any"
flag = request.form.getlist('flag')
flag = ','.join(flag) # making flag list a ',' separated string
url = "https://v2.jokeapi.dev/joke/{}?blacklistFlags={}".format(
cat, flag)
if flag:
flag = ','.join(flag) # making flag list a ',' separated string
url += '?blacklistFlags={}'.format(flag)
resp = requests.get(url)
data = resp.json()
if data.get('type') == 'single':
Expand Down

0 comments on commit 8ab814b

Please sign in to comment.