关于开代理后requests连接失败的问题解决方法

import requests

url = ‘https://buff.163.com’

直接运行会有 Caused by ProxyError(‘Cannot connect to proxy.’, OSError(0, ‘Error’)) 的错误

#res = requests.get(url)
#print(res.stauts_code)

方法1

proxy = { “http”: None, “https”: None}
res1 = requests.get(url,proxies=proxy)
print(res1.status_code)

方法2

session = requests.Session()
session.trust_env = False
response = session.get(url)
print(response.status_code)

你可能感兴趣的:(python爬虫,python,开发语言,后端)