IndentationError:使用“def”时,python中应出现缩进块错误

2024-05-23 15:14:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我是一个Python。我在学函数。下面是我的错误代码。你能帮我用“def”这个词来描述函数吗。我怎样才能解决这个问题?在

谢谢。在


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

^{pr2}$

Tags: 函数pytesthttpurldeflineusers
2条回答

为了精确起见,在python缩进中标记变量的范围等,因此需要对函数进行缩进

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

这同样适用于if else语句:

^{pr2}$

以及类、方法、try except块等,也一定要提交一种缩进形式,空格或制表符混合它们会产生奇怪的错误。在

python对制表符敏感,因此在def之后,代码需要使用tab 试试这个:

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

相关问题 更多 >