Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python错误syntaxerror';返回';外部功能_Python - Fatal编程技术网

python错误syntaxerror';返回';外部功能

python错误syntaxerror';返回';外部功能,python,Python,在代码下运行时,在函数外部获取语法错误'return' # Make the request to publish and check status code print("\tUploading...") server_response = requests.post(publish_url, data=payload, headers={'x-tableau-auth': auth_token,

在代码下运行时,在函数外部获取语法错误
'return'

# Make the request to publish and check status code 

    print("\tUploading...") 
    server_response = requests.post(publish_url, data=payload,  
                                    headers={'x-tableau-auth': auth_token, 'content-type': content_type}) 
    _check_status(server_response, 201) 
    return

您的错误清楚地表明您正在函数外部使用
return

由于您的代码不是一个简单的代码,我们将不得不猜测发生了什么

基本上有两种情况:

  • 您的
    返回指令缩进不正确。您可以通过缩进指令来修复它,直到它落在要从中返回的函数内
  • 例如:

    def foo:
        # do something inside the function 
        # ...
    
        return     # notice the indentation
    
  • 您的代码根本不起作用(就像您发布的代码一样),因此使用
    return
    是不正确的。(这不太可能,因为您刚刚从Github复制/粘贴了代码,但也有可能)

  • PD:顺便说一句,如果您使用
    return
    ,但实际上没有返回任何内容(如您发布的代码),那么您可以删除该指令。函数结束时将自动返回。

    您不清楚收到的错误的哪一部分?当
    return
    在函数之外使用时,您希望它会做什么?您是否也有意将
    return
    放在代码之外?XDIT是一个现成的脚本-从Github获得。请验证缩进。谢谢.publish_url=server+“/api/{0}/sites/{1}/workbooks.format(VERSION,site_id)publish_url+=”?workbookType={0}&overwrite=true.format(file_extension)#请求发布并检查状态码打印(“\tUploading…”)server_response=requests.post(publish_url,data=payload,headers)={'x-tableau-auth':auth_token,'content type':content_type})\u check_status(server_response,201)return编辑问题并在那里发布相关代码。并特别注意正确格式化和缩进代码(特别是因为您使用的是python)