无法通过网络将文件上传到 slack-api
Not able to upload a file to slack via web-api
我正在尝试使用 Web-API 将文件片段上传到 slack 频道,网址为 https://api.slack.com/methods/files.upload
payload_channel_caller = {'token': 'xoxpxxxxb1d8529c', 'channel':'C1PJ17FFT', 'file': "/home/nsingh/slack_shift/user_list" ,'title':'Shifters'}
print "This is a test"
requests.post('https://slack.com/api/files.upload', data=payload_channel_caller)
但是上面的代码无法上传文件,事实上它运行正确没有错误。
不确定这里有什么问题。
谁能帮帮我
修改点:
在您的脚本中,未读取您要上传的文件。当您的脚本是 运行 时,将检索以下响应。
{"ok":false,"error":"no_file_data"}
此时Slack传来的状态码是200,所以没有报错。以上几点反映出来的脚本如下
修改脚本:
import requests
uploadfile = "/home/nsingh/slack_shift/user_list" # Please input the filename with path that you want to upload.
with open(uploadfile, 'rb') as f:
param = {
'token': 'xoxpxxxxb1d8529c',
'channels': 'C1PJ17FFT',
'title': 'Shifters'
}
r = requests.post(
"https://slack.com/api/files.upload",
params=param,
files={'file': f}
)
print r.text
如果我误解了你的问题,我很抱歉。
我正在尝试使用 Web-API 将文件片段上传到 slack 频道,网址为 https://api.slack.com/methods/files.upload
payload_channel_caller = {'token': 'xoxpxxxxb1d8529c', 'channel':'C1PJ17FFT', 'file': "/home/nsingh/slack_shift/user_list" ,'title':'Shifters'}
print "This is a test"
requests.post('https://slack.com/api/files.upload', data=payload_channel_caller)
但是上面的代码无法上传文件,事实上它运行正确没有错误。
不确定这里有什么问题。
谁能帮帮我
修改点:
在您的脚本中,未读取您要上传的文件。当您的脚本是 运行 时,将检索以下响应。
{"ok":false,"error":"no_file_data"}
此时Slack传来的状态码是200,所以没有报错。以上几点反映出来的脚本如下
修改脚本:
import requests
uploadfile = "/home/nsingh/slack_shift/user_list" # Please input the filename with path that you want to upload.
with open(uploadfile, 'rb') as f:
param = {
'token': 'xoxpxxxxb1d8529c',
'channels': 'C1PJ17FFT',
'title': 'Shifters'
}
r = requests.post(
"https://slack.com/api/files.upload",
params=param,
files={'file': f}
)
print r.text
如果我误解了你的问题,我很抱歉。