以下是一段想用http://www.goubanjia.com/的免费ip试一下能否改变ip的代码
import requests
url='https://www.baidu.com/s?ie=utf-8&mod=1&isbd=1&isid=ade3ea7a000b60db&ie=utf-8&f=8&rsv_bp=1&tn=88093251_47_hao_pg&wd=ip&oq=ip&rsv_pq=ade3ea7a000b60db&rsv_t=5b017eIheFXHKmsg%2F8BPMMWIq2dAMuoGKKzn01j%2FnLb2GVMNMMAqZXe9NEUwYt0DqqdKmaMGZ7M1&rqlang=cn&rsv_enter=0&rsv_dl=tb&rsv_btype=t&bs=ip&rsv_sid=undefined&_ss=1&clist=505e05cef0e32bc5&hsug=&f4s=1&csor=2&_cr1=27777'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'}
# proxies对应的是http或s协议对应的ip
page_text=requests.get(url=url,headers=headers,proxies={"https":'120.83.109.201:9999'}).text
with open('./ip.html','w',encoding='utf-8')as aaa:
aaa.write(page_text)
然后就遇到了这个错误
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connection.py", line 170, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 96, in create_connection
raise err
File "D:\python\lib\site-packages\urllib3\util\connection.py", line 86, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "D:\python\lib\site-packages\urllib3\connection.py", line 353, in connect
conn = self._new_conn()
File "D:\python\lib\site-packages\urllib3\connection.py", line 182, in _new_conn
self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000021302D52400>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python\lib\site-packages\requests\adapters.py", line 449, in send
timeout=timeout
File "D:\python\lib\site-packages\urllib3\connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "D:\python\lib\site-packages\urllib3\util\retry.py", line 573, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: /s?ie=utf-8&mod=1&isbd=1&isid=ade3ea7a000b60db&ie=utf-8&f=8&rsv_bp=1&tn=88093251_47_hao_pg&wd=ip&oq=ip&rsv_pq=ade3ea7a000b60db&rsv_t=5b017eIheFXHKmsg%2F8BPMMWIq2dAMuoGKKzn01j%2FnLb2GVMNMMAqZXe9NEUwYt0DqqdKmaMGZ7M1&rqlang=cn&rsv_enter=0&rsv_dl=tb&rsv_btype=t&bs=ip&rsv_sid=undefined&_ss=1&clist=505e05cef0e32bc5&hsug=&f4s=1&csor=2&_cr1=27777 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000021302D52400>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。')))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:/python/untitled/代理操作.py", line 5, in <module>
page_text=requests.get(url=url,headers=headers,proxies={"https":'120.83.109.201:9999'}).text
File "D:\python\lib\site-packages\requests\api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "D:\python\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "D:\python\lib\site-packages\requests\sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "D:\python\lib\site-packages\requests\adapters.py", line 510, in send
raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: /s?ie=utf-8&mod=1&isbd=1&isid=ade3ea7a000b60db&ie=utf-8&f=8&rsv_bp=1&tn=88093251_47_hao_pg&wd=ip&oq=ip&rsv_pq=ade3ea7a000b60db&rsv_t=5b017eIheFXHKmsg%2F8BPMMWIq2dAMuoGKKzn01j%2FnLb2GVMNMMAqZXe9NEUwYt0DqqdKmaMGZ7M1&rqlang=cn&rsv_enter=0&rsv_dl=tb&rsv_btype=t&bs=ip&rsv_sid=undefined&_ss=1&clist=505e05cef0e32bc5&hsug=&f4s=1&csor=2&_cr1=27777 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000021302D52400>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。')))
想问一下怎么开启,我看了下代码和b站的某视频没差。