O'Reilly logo

Python Automation Cookbook by Jaime Buelta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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  ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required