Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
12423 Lượt xem

Code is 

def import_file(self): 

 file = io.BytesIO(base64.decodestring(self.file)) 

 

 reader = csv.reader(file, delimiter=',') 


 csv.field_size_limit(sys.maxsize) 

 skip_header = True 

 for row in reader:



Error is 


File "/opt/odoo13/odoo-custom-addons/import_product_image/models/import_image.py", line 52, in import_file
    for row in reader:
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
Ảnh đại diện
Huỷ bỏ

do you need to import images from csv file?

Tác giả

yes its your module converting into v13 from v10

Câu trả lời hay nhất

Hi,

Try the following code which import image from csv file, in the following code image url is given in csv file, you can change the code accordingly.

file = base64.b64decode(self.binary_field_name)
file_string = file.decode('utf-8')
file_string = file_string.split('\n')
http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())
if "http://" in file_item.split(",")[0] or "https://" in file_item.split(",")[0]:
link = file_item.split(",")[0]
image_response = http.request('GET', link)
image_thumbnail = base64.b64encode(image_response.data)

Regards

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất


Try this

    @api.multi
def read_file(self):
if self.attachment:
wb = open_workbook(file_contents = base64.decodestring(self.attachment))
for s in wb.sheets():
values = []
first_row = [] # Header
for col in range(s.ncols):
first_row.append(s.cell_value(0,col) )
data =[]
for row in range(1, s.nrows):
elm = {}
for col in range(s.ncols):
elm[first_row[col]]=s.cell_value(row,col)
data.append(elm)
# print data


Ảnh đại diện
Huỷ bỏ
Tác giả

my code is csv base...

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 25
2512
0
thg 5 23
2278
3
thg 3 25
23847
1
thg 11 22
2178
1
thg 5 22
5693