python upload file遇到的坑,整理如下

 1     def UpLoadImg_advancedupload(self,corpid):
 2         '''
 3         :param corpid: 
 4         :return: 
 5         '''
 6         url = Merchant.host['test_host']+Merchant().http_map['advancedupload']
 7         fileName = 'C:\Users\Administrator\PycharmProjects\pythonProject\configs\testFile\注册(1).bmp'
 8         file = open(fileName,'rb')
 9         files ={
10             'file':('注册(1).bmp', file, 'image/bmp')
11                }
12         params ={
13             'corpId': corpid
14         }
15         try:
16             # 也可不设置head属性
17             result = requests.post(url, data=params, files=files).json()
18             print(f'response:{result}')
19             return result
20         except Exception as e:
21             print(e)
22         finally:
23             file.close()

 反复遇到权限问题,经过多处查询资料  整理记录下

原文地址:https://www.cnblogs.com/by170628/p/14673832.html