Demand
Function.py
import urllib ,requests
def upload_file(cls, file_name, file_path, parameter, parameter_name,file_type, headers={},
path='/index.php?'):
params = urllib.urlencode(parameter)
url = 'http://api.123.com' + path+params
file_path_name = file_path+file_name
files = {
parameter_name: (file_name, open(file_path_name, 'rb'), file_type),
}
response = requests.post(url, files=files, headers=headers)
return response
Use:
file_name = 'test.png'
file_path = "/home/git/AutoTest/Misc/"
parameter = {"r": "A/B"}
parameter_name = 'pic'
file_type='image/png'
response = upload_file(file_name, file_path, parameter, parameter_name,
file_type=, headers=cookie)
print response
Succ:
- txt文件:
file_type= 'text/plain'
@ 雾霾--2016-11-04 16:40:32