我正在尝试使用请求模块发送csv文件,但我一直得到500:内部服务器错误。我尝试过使用cURL并且工作正常。
下面是我的python代码:
import requests
filepath = 'ABC.csv'
with open('ABC.csv','rb') as input_file:
response = requests.put('http://....', headers = {'Content-Disposition': 'attachment;filename=Cu_temp.csv', 'content-type':'application/csv'},files={'docfile': input_file})
response.raise_for_status()
对我有用的curl命令是;
curl -X PUT -H "Content-Disposition: attachment;filename=ABC.csv" -H "Content-Type:application/csv" -T ABC.csv http://...
以下是我得到的错误;
HTTPError Traceback (most recent call last)
<ipython-input-24-077dff9ba8c1> in <module>()
13 )
---> 14 response.raise_for_status()
C:\Anaconda2\lib\site-packages\requests\models.pyc in raise_for_status(self)
838
839 if http_error_msg:
--> 840 raise HTTPError(http_error_msg, response=self)
841
842 def close(self):
HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: http://.....
在评论中从@brunodesthuilliers的建议编辑我的代码后,现在我收到400客户端错误: 这是我的新代码
import requests
filepath = 'ABC.csv'
url = 'http://...'
with open('ABC.csv','rb') as input_file:
files= {'file': ('ABC.csv', 'application/csv','attachment;filename=ABC.csv')}
response = requests.put(url,files=files)
response.raise_for_status()
任何想法,出了什么问题?