I’m upgrading from slackclient 1.3.1 to 2.9.3 using this guide.
before I had this function:
     def upload_file(self, file, filename, title, channel):
         return self.slack_client.api_call(
             "files.upload",
             channels=channel,
             filename=filename,
             title=title,
             file=file)
which I tried to migrate to:
    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})
the function is called with something like this:
with open("/vm-root/app/" + log, 'rb') as f:
    instance.upload_file(f, log, log, channel)
However, I get:
Object of type ‘BufferedReader’ is not JSON serializable
I am guessing it is related to the way I pass the file parameter. How should I be doing it?
Advertisement
Answer
Solved, the parameters were wrong:
    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})
