我正在編寫一個Python腳本,用於執行批量照片上傳。 我想讀取圖像並將其轉換爲字節數組。任何建議將不勝感激。用於將圖像轉換爲字節數組的Python腳本
#!/usr/bin/python
import xmlrpclib
import SOAPpy, getpass, datetime
import urllib, cStringIO
from PIL import Image
from urllib import urlopen
import os
import io
from array import array
""" create a proxy object with methods that can be used to invoke
corresponding RPC calls on the remote server """
soapy = SOAPpy.WSDL.Proxy('localhost:8090/rpc/soap-axis/confluenceservice-v2?wsdl')
auth = soapy.login('admin', '[email protected]')
你爲什麼要這樣做?這將如何幫助你上傳? theres沒有足夠的數據有意義的答案 – WeaselFox
@WeaselFox:我想讀取一個圖像文件並將其轉換爲Byte數組。 –
#pictureData = xmlrpclib.Binary(open('C:/BulkPhotoUpload/UserPhotos/admin.png')。read())。decode('utf-8') url ='C:/ BulkPhotoUpload/UserPhotos/admin。 png' pictureData = unicode(str(open(url,「rb」))) print type(pictureData) profilePictureAdded = soapy.addProfilePicture(auth,'admin','avatar.png','image/png', pictureData) if profilePictureAdded: print「成功添加新的個人資料圖片...」 其他: 打印「無法添加新的個人資料圖片...」 –