0

I'm an in python. I'm trying to learn using functions. My code block and error are below. Could you help me please How can I use "def" word to describe a function. How can I fix the problem?

Thanks.


 File "C:/Users/tCLARABUL/PycharmProjects/test/WScall.py", line 8
    url == "http://zzzz:80/xxx/yyy?WSDL"
      ^
IndentationError: expected an indented block

import requests

def inka(ntfid):

url = "http://zzzz:80/xxx/yyy?WSDL"

headers = yyy

body = "xxx""

response = requests.post(url, data=body, headers=headers)

return response.text

print(inka(122727))
CodeSamurai777
  • 3,285
  • 2
  • 24
  • 42

2 Answers2

2

To be precise in python indentation mark the scope of variables etc. So you need an indent for functions

def inka(ntfid):
    url = "http://zzzz:80/xxx/yyy?WSDL"
    headers = yyy
    body = "xxx""
    response = requests.post(url, data=body, headers=headers)

    return response.text

The same applies to if else statements:

if:
   pass
else:
   pass

And classes, methods, try except block etc. Also be sure to commit to one form of indents spaces or tabs mixing them gives odd errors.

CodeSamurai777
  • 3,285
  • 2
  • 24
  • 42
0

python is tab sensitive so after def the code needs to be with tab try this:

import requests

def inka(ntfid):
    url = "http://zzzz:80/xxx/yyy?WSDL"
    headers = yyy
    body = "xxx""
    response = requests.post(url, data=body, headers=headers)

    return response.text

print(inka(122727))
Tom St
  • 908
  • 8
  • 15
  • "Needs to be with tab" is misleading and technically wrong. Spaces can be used as well and are actually the [recommended](https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces) choice. – FlyingTeller Jul 28 '18 at 12:05
  • thank you for your answer. It is fixed. – Levent Arabul Jul 28 '18 at 12:05
  • FlyingTeller - detail mate :D code's copied... tabs added with spaces, anyone will tell you that technically python is tabs sensitive so you can argue for spaces if you want, but thats the official definition :) – Tom St Jul 28 '18 at 12:07