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.
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)
x in one of the [ ])x in each of the [ ])Filling out the following details about bugs will help us solve your issue sooner.
slackclient version: 2.0.0
python version: 3.7.0
OS version(s): Windows 10
Receive file object for the newly uploaded file
API error file_not_found
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.
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.