CentOs服务器上的松弛文件上传失败

时间:2020-01-06 16:46:42

标签: python-2.7 centos slack-api

我正在尝试通过API将文件上传到Slack,并且相同的脚本在本地可以正常工作(文件正确上传),但是从Server运行时失败,返回:

{u'ok': False, u'error': u'no_file_data'}

这里使用了2种功能(一种将内容写入tmp文件夹,另一种将内容上传到所选频道)

def writeToFile():
    with open(output_file, 'rb') as rf:
        with open('/tmp/' + output_file, "w") as wf:
            wf.write(rf.read())


def upload_file():
    with open('/tmp/' + output_file) as file_content:
        r = client.api_call(
            "files.upload",
            channels=channel,
            file=file_content,
            filetype='xlsx',
            title=output_file
        )
        logging.info(r)

似乎该文件已通过writeToFile正确写入tmp文件夹,但问题发生在upload_file中。

我也可以阅读

with open('/tmp/' + output_file) as file_content:
    print file_content.read() 

正确打印文件内容。因此问题出在api调用上。

我在本地有MacOS和服务器Linux Centos。我在两者上都使用Python 2.7.10。

0 个答案:

没有答案