桐生战兔丶 发表于 2021-8-25 09:21:23

请问大佬们知道这个报错该咋解决吗

本帖最后由 桐生战兔丶 于 2021-8-25 09:35 编辑

如图
import requests as req
import os
import json
import re
import time as ti

openfile = open ('C:\\Users\\surface\\Desktop\\GoooodDesigh\\items2.json')
# origin
ori= json.load(openfile)
urllist1 = str(ori['urllist'])
#urllist2 = urllist1.split(',')
#urllist = re.search(r"\[\''([^']+)\'",urllist2)
imglist1 = str(ori['imglist1'])

imglist = imglist1.split(',')

namelist1 = str(ori['namelist1'])
namelist = namelist1.split(',')


#imgpackage = os.mkdir('imgpackage')

headers = {}
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3875.400 QQBrowser/10.8.4492.400'


for each in range(len(imglist)):

    if each == 1 or each == 8:
      img = str(imglist)
      img1 = img
    else:
      img = str(imglist)
      img1 = img
    imgre = req.get(img1,headers = headers)

    imgdata = open('C:\\Users\\surface\\Desktop\\imgpackage\\'+ str(each)+'.'+str(namelist+'.jpg','wb'))

    imgencdde = img1.decode(img1,'utf-8')

    imgdata.write(imgencdde)
   
    imgdata.close()

    time.sleep(1)



报错文本:

        Traceback (most recent call last):
File "C:\Users\surface\Desktop\shell.py", line 37, in <module>
    imgdata = open('C:\\Users\\surface\\Desktop\\imgpackage\\'+ str(each)+'.'+str(namelist+'.jpg','wb'))
TypeError: decoding str is not supported

wp231957 发表于 2021-8-25 09:28:14

为啥要发图片呢   发文本代码和文本错误信息不好吗

桐生战兔丶 发表于 2021-8-25 09:35:51

wp231957 发表于 2021-8-25 09:28
为啥要发图片呢   发文本代码和文本错误信息不好吗

已更正

wp231957 发表于 2021-8-25 10:04:25

桐生战兔丶 发表于 2021-8-25 09:35
已更正

items2.json   这个文件 还要发一下

南归 发表于 2021-8-25 15:49:37

'wb'后的一个)应该放在each]后
页: [1]
查看完整版本: 请问大佬们知道这个报错该咋解决吗