python爬虫批量下载图片时出错,ProxyError: HTTPSConnectionPool port=443

终端报错如下:


requests.exceptions.ProxyError: HTTPSConnectionPool(host='zfile.cosersets.com', port=443): Max retries exceeded with url: /file/1/Fushii_%E6%B5%B7%E5%A0%82/%E6%B4%9B%E4%B8%BD%E5%A1%94/01.webp (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(54, 'Connection reset by peer')))

部分源代码如下:

import os
from PIL import Image
from io import BytesIO
import requests
import time

from bs4 import BeautifulSoup
from selenium import webdriver

def down(path,src,i,work):
    print('下载中')
    response = requests.get(src, verify=False)
    image = Image.open(BytesIO(response.content))
    end = work+i
    image.save('{}/{}.webp'.format(path,end))

添加 os.environ['NO_PROXY'] = '你的请求域名' (例如:os.environ['NO_PROXY'] = '51shucheng.net')尝试一下