python中的Linux curl-F equavilant命令

python中的Linux curl-F equavilant命令,python,python-2.7,urllib2,urllib,Python,Python 2.7,Urllib2,Urllib,我需要在python程序中编写linux命令的等效代码 curl -F file=@/path/to/file http://localhost:8090/tasks/create/file 我已经使用urllib将此命令转换为python import urllib import urllib2 url='http://localhost:8090/tasks/create/file' values={'file' : '@/home/hacker/sample/00.EXE'} data=

我需要在python程序中编写linux命令的等效代码

curl -F file=@/path/to/file http://localhost:8090/tasks/create/file
我已经使用urllib将此命令转换为python

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)
但这并不能完成所需的工作,并且在python控制台上会显示以下错误

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

为什么不使用?请参见以下答案:问题已解决,非常感谢:
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