Python 使用slack upload api时,上载文件名包含日语到slack时,没有\u文件\u数据错误
我正试图上传一个名为包含日语字符的文件到slack,比如:Python 使用slack upload api时,上载文件名包含日语到slack时,没有\u文件\u数据错误,python,lambda,slack-api,Python,Lambda,Slack Api,我正试图上传一个名为包含日语字符的文件到slack,比如:/tmp/結果.xlsx 带有无文件数据的请求响应错误且无文件发送到slack。 但当我将文件名更改为/tmp/result.xlsx时,一切都很好。 我不知道出了什么问题 job.py from botocore.vendored import requests import urllib.request def execute(): params = {'token': 'my-slack-token',
/tmp/結果.xlsx
带有无文件数据的请求响应
错误且无文件发送到slack。
但当我将文件名更改为/tmp/result.xlsx
时,一切都很好。
我不知道出了什么问题
job.py
from botocore.vendored import requests
import urllib.request
def execute():
params = {'token': 'my-slack-token',
'channels': 'test-channel', 'initial_comment': 'test-comment'}
file_name = "/tmp/結果.xlsx"
urllib.request.urlretrieve(
'http://download-url', file_name)
file = {'file': open(file_name, 'rb')}
res = requests.post(url="https://slack.com/api/files.upload", params=params, files=file)
print(res.text)
import job
def execute(event, context):
job.execute()
return {
'statusCode': 200,
'body': "Done!"
}
和main.py
from botocore.vendored import requests
import urllib.request
def execute():
params = {'token': 'my-slack-token',
'channels': 'test-channel', 'initial_comment': 'test-comment'}
file_name = "/tmp/結果.xlsx"
urllib.request.urlretrieve(
'http://download-url', file_name)
file = {'file': open(file_name, 'rb')}
res = requests.post(url="https://slack.com/api/files.upload", params=params, files=file)
print(res.text)
import job
def execute(event, context):
job.execute()
return {
'statusCode': 200,
'body': "Done!"
}
当这个lambda被触发时,我得到了一个结果{“ok”:false,“error”:“no_file_data”}
,但是如果我将文件名更改为result.xlsx
,一切都会好的
谢谢你的帮助 代码可能是UTF8编码问题您使用的是Python2还是Python3?我使用的是Python3.7