request proxy(代理)報錯解決辦法
阿新 • • 發佈:2021-02-03
python3.7.6版本,我們使用request庫設定代理ip的時候,可能會遇到urllib3.exceptions.ProxySchemeUnknown: Not supported proxy scheme None
錯誤,這是因為底層修改了url解析模式,使得proxy代理解析失敗導致。
報錯原始碼:
poolmanager.py
if proxy.scheme not in ("http", "https"):
raise ProxySchemeUnknown(proxy.scheme)
exceptions. py
class ProxySchemeUnknown(AssertionError, ValueError):
"ProxyManager does not support the supplied scheme"
# TODO(t-8ch): Stop inheriting from AssertionError in v2.0.
def __init__(self, scheme):
message = "Not supported proxy scheme %s" % scheme
super (ProxySchemeUnknown, self).__init__(message)
解決方案是:需要將代理寫成http://+ip+port這種形式,不能去掉前面的http://
如果使用代理的話:
proxies = {
"http":"http://127.0.0.1:8080",
"https":"https://127.0.0.1:8080",
}
request.get(url,proxies=proxies)