在Python中使用请求模块时发生500内部服务器错误

在Python中使用请求模块时发生500内部服务器错误,python,http,curl,request,Python,Http,Curl,Request,我试图通过使用请求模块发送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文件,但我一直收到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://.....

你知道哪里出了问题吗?

你能添加你从服务器上得到的错误吗?你为什么要打开文件?我认为您想提供文件名,但您正试图将其作为附件发送。因此,在put请求中,您传递了一个文件句柄。是这样吗?看起来像是
requests
希望在
文件中设置各种标题字段,而不是作为标题:@joelgoldstick:是的,我想作为附件发送。@brunodesshuilliers:你的意思是像
files={'file':('ABC.csv',open'ABC.csv','application/csv')}r=requests.post(url,files=files)
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()