I need to write the equivalent code of linux command in my python program command is
curl -F file=@/path/to/file http://localhost:8090/tasks/create/file
I have translated this command into python using urllib as
import urllib
import urllib2
url='http://localhost:8090/tasks/create/file'
values={'file' : '@/home/hacker/sample/00.EXE'}
data=urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
but this does not do the required work and following error is printed on python console
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib64/python2.6/urllib2.py", line 397, in open
response = meth(req, response)
File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib64/python2.6/urllib2.py", line 435, in error
return self._call_chain(*args)
File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error
while on the server console following error is given
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/bottle.py", line 862, in _handle
return route.call(**args)
File "/usr/lib/python2.6/site-packages/bottle.py", line 1729, in wrapper
rv = callback(*a, **ka)
File "./api.py", line 69, in tasks_create_file
temp_file_path = store_temp_file(data.file.read(), data.filename)
AttributeError: 'unicode' object has no attribute 'file'
127.0.0.1 - - [06/Aug/2014 11:53:01] "POST /tasks/create/file HTTP/1.1" 500 758