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()

 反復遇到權限問題,經過多處查詢資料  整理記錄下


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM