Python-slack-sdk: file_not_found after uploading file

Created on 30 Jul 2019  路  3Comments  路  Source: slackapi/python-slack-sdk

Description

After uploading a file successfully with files_upload() I am getting a file_not_found error when trying to use files_info() on the newly uploaded file.

But when I call the API method files.info for the same file ID it works fine.

Note I have the same issue with other files method of the library, e.g. files_sharedPublicURL().

I am rather new to Python so I might be missing something here, but what? Any help would be highly appreciated.

Code

Here is an example code to reproduce the error (requires an image file in the same folder).

import slack
import os
import requests

# init slack client with access token
slack_token = os.environ['SLACK_TOKEN']
client = slack.WebClient(token=slack_token)

# upload file
response = client.files_upload(    
    file="Stratios_down.jpg"
)
assert response["ok"]
slack_file = response["file"]
file_id = slack_file["id"]
print(file_id)

# get info with slackclient fails
try:
    print("trying files.info with client lib")
    response = client.files_info(id=file_id)
    assert response["ok"]
    print(response["file"])
except Exception as ex:
    print("ERROR: ", ex)

# get info with request to API works
try:
    print("trying files.info with direct API request")
    res = requests.get(
        url="https://slack.com/api/files.info",
        params={
            "token": slack_token,
            "file": file_id
        }
    )
    response = res.json()
    assert response["ok"]
    print(response["file"])
except Exception as ex:
    print("ERROR: ", ex)

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [x] question
  • [ ] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

slackclient version: 2.0.0

python version: 3.7.0

OS version(s): Windows 10

Steps to reproduce:

  1. upload new file with files_upload
  2. call files_info for the newly uploaded file

Expected result:

Receive file object for the newly uploaded file

Actual result:

API error file_not_found

Attachments:

  • / -
question

Most helpful comment

I upgraded the slackclient package from 2.0.0 to 2.1.0 and now it works.
Apparently this was a bug in the previous version that is fixed in the current version.
@clavin you pointing out the the current source code asks for different arguments gave me the importent clue. thanks again for your help.

All 3 comments

When you call client.files_info, you're passing id=file_id, whereas in your other example with requests you pass "file": file_id to the API. 馃 Checking the source, the argument is named file 馃挕 so thus the proper call should be:

response = client.files_info(file=file_id)

Let me know if that works 馃憤! (Or still produces an error 馃槵.)

Thanks for your answer. It does not solve my problem though, because on my system the method files_info is requesting the mandatory argument id, not file.

See here:
https://i.imgur.com/4wmGsSw.png

Any idea how this can be fixed?

I upgraded the slackclient package from 2.0.0 to 2.1.0 and now it works.
Apparently this was a bug in the previous version that is fixed in the current version.
@clavin you pointing out the the current source code asks for different arguments gave me the importent clue. thanks again for your help.

Was this page helpful?
0 / 5 - 0 ratings