How to do it...

  1. Run the script, which will generate an error:
$ python debug_skills.pyTraceback (most recent call last): File "debug_skills.py", line 26, in <module> raise Exception(f'Error accessing server: {result}')Exception: Error accessing server: <Response [405]>
  1. Analyze the status code. We get 405, which means that the method we sent is not allowed. We inspect the code and realize that for the call in line 24, we used GET, when the proper one is POST (as described in the URL). Replace the code with the following:
# ERROR Step 2. Using .get when it should be .post# (old) result = requests.get('http://httpbin.org/post', json=data)result = requests.post('http://httpbin.org/post', json=data)

We keep the old buggy code commented with ...

Get Python Automation Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.