Python requests设置代理的方法步骤
指导文档:
http://docs.python-requests.org/en/master/user/advanced/的Proxies
http://docs.python-requests.org/en/latest/user/advanced/的SSLCertVerification
requests设置代理
importrequests proxies={'http':'http://localhost:8888','https':'http://localhost:8888'} url='http://www.baidu.com' requests.post(url,proxies=proxies,verify=False)#verify是否验证服务器的SSL证书
执行结果:
基于selenium的代理设置:
fromseleniumimportwebdriver proxy='124.243.226.18:8888' option=webdriver.ChromeOptions() option.add_argument('--proxy-server=http://'+proxy) driver=webdriver.Chrome(options=option) driver.get('http://httpbin.org/get')
python3.8requestproxy(代理)失效解决方案
在使用python3.8版本的时候,我们使用request库的时候,可能会遇到
urllib3.exceptions.ProxySchemeUnknown:NotsupportedproxyschemeNone
下面这样的错误,这是游戏底层修改了url解析模式,导致proxy代理解析失败导致的。
解决方案是:
如果不使用代理,那么就可以改成
proxies={ "http":"", "https":"", } request.get(url,proxies=proxies)
如果使用代理的话,就可以修改成:
proxies={ "http":"http://127.0.0.1:1080", "https":"https://127.0.0.1:1080", }
需要注意的是,一定要写成http://+ip+port这种形式,不能去掉前面的http://,否则就会产生错误。
到此这篇关于Pythonrequests设置代理的方法步骤的文章就介绍到这了,更多相关Pythonrequests设置代理内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。