无法使用请求在 usergrid 上 post 文件
unable to post file on usergrid using requests
我可以 post 文件 curl
curl -X POST -i -F name='memo.txt' -F file=@/home/tester/Desktop/memo.txt
'http://localhost:8080/***/***/concerts/008?
access_token=YWMtraI2DF21EeWx_Rm4tdnmrwAAAVACjcyGG8TpdXJBXdjnRJ2SeqIAZI1T8Xk'
但是当我用 requests.post
尝试同样的事情时,文件没有上传到服务器。有谁知道为什么会这样。
import requests
url = 'http://localhost:8080/***/***/concerts/008'
files = {
'memo.txt': open('/home/tester/Desktop/memo.txt', 'rb'),
'name': 'memo.txt'
}
r = requests.post(
url, files=files,
params=dict(access_token='YWMtraI2DF21EeWx_Rm4tdnmrwAAAVACjcyGG8TpdXJBXdjnRJ2SeqIAZI1T8Xk')
)
您似乎缺少 name
字段,请将其添加到您的 files
词典或新的 data
词典(两者都可以)。您的文件应命名为 file
:
import requests
url = 'http://localhost:8080/***/***/concerts/008'
files = {'file': open('/home/tester/Desktop/memo.txt','rb')}
data = {'name': 'memo.txt'}
params = {'access_token': 'YWMtraI2DF21EeWx_Rm4tdnmrwAAAVACjcyGG8TpdXJBXdjnRJ2SeqIAZI1T8Xk'}
r = requests.post(url, data=data, files=files, params=params)
或
import requests
url = 'http://localhost:8080/***/***/concerts/008'
files = {
'file': open('/home/tester/Desktop/memo.txt','rb'),
'name': 'memo.txt'
}
params = {'access_token': 'YWMtraI2DF21EeWx_Rm4tdnmrwAAAVACjcyGG8TpdXJBXdjnRJ2SeqIAZI1T8Xk'}
r = requests.post(url, files=files, params=params)
我可以 post 文件 curl
curl -X POST -i -F name='memo.txt' -F file=@/home/tester/Desktop/memo.txt
'http://localhost:8080/***/***/concerts/008?
access_token=YWMtraI2DF21EeWx_Rm4tdnmrwAAAVACjcyGG8TpdXJBXdjnRJ2SeqIAZI1T8Xk'
但是当我用 requests.post
尝试同样的事情时,文件没有上传到服务器。有谁知道为什么会这样。
import requests
url = 'http://localhost:8080/***/***/concerts/008'
files = {
'memo.txt': open('/home/tester/Desktop/memo.txt', 'rb'),
'name': 'memo.txt'
}
r = requests.post(
url, files=files,
params=dict(access_token='YWMtraI2DF21EeWx_Rm4tdnmrwAAAVACjcyGG8TpdXJBXdjnRJ2SeqIAZI1T8Xk')
)
您似乎缺少 name
字段,请将其添加到您的 files
词典或新的 data
词典(两者都可以)。您的文件应命名为 file
:
import requests
url = 'http://localhost:8080/***/***/concerts/008'
files = {'file': open('/home/tester/Desktop/memo.txt','rb')}
data = {'name': 'memo.txt'}
params = {'access_token': 'YWMtraI2DF21EeWx_Rm4tdnmrwAAAVACjcyGG8TpdXJBXdjnRJ2SeqIAZI1T8Xk'}
r = requests.post(url, data=data, files=files, params=params)
或
import requests
url = 'http://localhost:8080/***/***/concerts/008'
files = {
'file': open('/home/tester/Desktop/memo.txt','rb'),
'name': 'memo.txt'
}
params = {'access_token': 'YWMtraI2DF21EeWx_Rm4tdnmrwAAAVACjcyGG8TpdXJBXdjnRJ2SeqIAZI1T8Xk'}
r = requests.post(url, files=files, params=params)