Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.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 使用slackclient 2.x上载文件_Python_Slack Api - Fatal编程技术网

Python 使用slackclient 2.x上载文件

Python 使用slackclient 2.x上载文件,python,slack-api,Python,Slack Api,我正在使用从slackclient1.3.1升级到2.9.3 在我使用此功能之前: def upload_file(self, file, filename, title, channel): return self.slack_client.api_call( "files.upload", channels=channel, filename=filename,

我正在使用从
slackclient
1.3.1
升级到
2.9.3

在我使用此功能之前:

     def upload_file(self, file, filename, title, channel):
         return self.slack_client.api_call(
             "files.upload",
             channels=channel,
             filename=filename,
             title=title,
             file=file)
我尝试迁移到:

    def upload_file(self, file, filename, title, channel):
    return self.web_client.api_call(
        "files.upload",
        json={'channels': channel,
              'filename': filename,
              'title': title,
              'file': file})
函数的调用方式如下:

with open("/vm-root/app/" + log, 'rb') as f:
    instance.upload_file(f, log, log, channel)
然而,我得到:

“BufferedReader”类型的对象不可JSON序列化


我猜这与我传递
文件
参数的方式有关。我应该怎么做?

解决了,参数错误:

    def upload_file(self, file, filename, title, channel):
    return self.web_client.api_call(
        "files.upload",
        files={'file': file},
        data={'channels': channel,
              'filename': filename,
              'title': title})