【已解决】urllib3.exceptions.ProxySchemeUnknown:Proxy URL had no scheme,should start with http://or https

问题描述

解决办法

        方法一,按照提示添加对应的前缀

        通过排查发现了原因,就是在Python3.6以后,在使用代理时,requests.get(url=url, headers=headers, proxies=…)中proxies的参数值发生了变化,3.6包括之前,proxies={‘https’: ‘127.0.0.1:8080’}或者proxies={‘http’: ‘127.0.0.1:8080’}即可,但是这样的字典类型并不适用于Python3.7及以上的版本。

        在Python3.7及以上版本,必须要在ip:port前面加上http://或者https://,绝对不能去掉前面的http://或者https://,即Python3.7后必须使用proxies={‘http’: ‘http://127.0.0.1:8080’}或者proxies={‘https’: ‘https://127.0.0.1:8080’},比如

#Python3.6 不需要加http://
proxy_pool = {
	'http': '127.0.0.1:8080',
	'https': '127.0.0.1:8080',
}
response = requests.get(url=url, headers=headers, proxies=random.choice(proxy_pool)) #proxies={'http': '127.0.0.1:8080'}

#Python3.7及以上 必须加上http://,不加就会报错
proxy_pool = {
	'http': 'http://127.0.0.1:8080',
	'https': 'https://127.0.0.1:8080',
}
response = requests.get(url=url, headers=headers, proxies=random.choice(proxy_pool)) #proxies={'http': 'http://127.0.0.1:8080'}
        方法二,更新需要的requests包
pip3 install --upgrade requests
        方法三,重置网络代理
unset http_proxy

unset https_proxy

        方法四,指定网络代理 

set HTTPS_PROXY=http://username:password@proxy.example.com:8080 
set https_proxy=http://username:password@proxy.example.com:8080

Where proxy.example.com is the proxy address (in my case it is localhost) and 8080 is my port.

You can figure out your username by typing echo %username% in your command line. As for the proxy server, on Windows, you need to go to "Internet Options" -> "Connections" -> LAN Settings and tick "Use a proxy server for your LAN". There, you can find your proxy address and port.

完结撒花

        每一只自由的灵魂都应该被尊重

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值