I am trying to send a csv file by using request module but I keep getting 500: Internal Server Error. I have tried using cURL and it worked fine.
Below is my python code:
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()
The curl command that worked for me is;
curl -X PUT -H "Content-Disposition: attachment;filename=ABC.csv" -H "Content-Type:application/csv" -T ABC.csv http://...
Below is the error that I am getting;
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://.....
After editing my code from suggestions from @brunodesthuilliers in the comments, now I am getting 400 Client error: Here is my new code
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()
Any idea, what is going wrong?