我正在尝试在使用用户输入打开的每个浏览器窗口上添加一个身份验证代理,但我收到这些错误......
[20792:21516:1222/011708.284:ERROR:ssl_client_socket_impl.cc(935)] handshake failed; returned -1, SSL error code 1, net_error -202
DEBUG:seleniumwire.proxy.handler:accounts.google.com:443 200
我启用了日志记录,我看到我什至没有使用根据它提供的日志从.txt文件中导入的代理......
7.0.0.1:50988", "noProxy": ""}, "acceptInsecureCerts": true}}, "desiredCapabilities": {"browserName": "chrome", "version": "", "platform": "ANY", "proxy": {"proxyType": "manual", "httpProxy": "127.0.0.1:50988", "sslProxy": "127.0.0.1:50988", "noProxy": ""}, "acceptIns
ecureCerts": true}}
例如,如果用户输入 1,则将打开 1 个窗口,其中包含代理列表中的代理"代理.txt"。
这是我的完整代码。
from seleniumwire import webdriver
from selenium.webdriver.chrome.options import Options
import logging
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from fake_useragent import UserAgent
import time
import random
from bs4 import BeautifulSoup
logging.basicConfig(level=logging.DEBUG)
chrome_path = r"chromedriver.exe"
times = ""
start_page = ""
settings = Options()
# proxy = Proxy()
pro_sheet = open("proxies.txt", "r")
new_proxy = []
for line in pro_sheet:
new_proxy.append(line)
def start_pages(target_page):
new = []
ip = ''
port = ''
username = ''
password = ''
j = 0
for x in range(0, len(page_number)):
j = j + 1
time.sleep(3)
print("Attempting to add fake userAgent...")
ua = UserAgent()
user_agent = ua.random
print("Successfully added fake userAgent...")
time.sleep(1)
print("Attempting to add capabilities and chrome options...")
settings.add_argument(f'user-agent={user_agent}')
settings.add_experimental_option("detach", True)
settings.add_argument("window-size=600,600")
settings.add_argument('--disable-extensions')
settings.add_argument('--profile-directory=Default')
settings.add_argument("--disable-plugins-discovery")
settings.add_argument("--proxy-server=%s" % random.choice(*new_proxy))
settings.add_argument("ignore-certificate-errors-spki-list")
print("Successfully added chrome arguments and capabilities/options...")
print("Attempting to detach chrome...")
settings.add_experimental_option("detach", True)
print("Successfully Detached chrome...")
time.sleep(1)
# print("Attempting to to initiate headless mode")
# chrome_options.add_argument("--headless")
# print('Initiated headless mode')
print("Attempting to add proxy...")
time.sleep(1)
for p in range(len(new_proxy)):
new = new_proxy[p]
# print(new)
n_p = new.split(':')
for b in range(0, len(n_p)):
ip = n_p[0]
port = n_p[1]
username = n_p[2]
password = n_p[3]
options = {
'proxy': {
'http': ip + ':' + port + ':' + username + ':' + password,
'https': ip + ':' + port + ':' + username + ':' + password,
}
}
driver = webdriver.Chrome(chrome_path, seleniumwire_options=options)
driver.set_window_position(0, 0)
time.sleep(1)
print("Successfully added proxy...")
print("Browser number " + str(j) + ", is using proxy: " + str(*new_proxy))
time.sleep(1)
print("Browser number " + str(j) + " has opened successfully...")
while times == "":
times = input("How many pages do you want?n")
# url = input("Yeezy Supply or Adidas?""nEither 'YS' or 'Adidas'n")
# url_choice = url.lower()
page_number = list()
for i in range(0, int(times)):
page_number.append(times)
# if url_choice == 'ys':
# start_page = 'https://yeezysupply.com/'
# start_pages(start_page)
# elif url_choice == 'adidas':
# start_page = 'https://www.adidas.com/yeezy'
# start_pages(start_page)
start_page: str = 'https://www.adidas.com/yeezy'
start_pages(start_page)
当我制作一个 Android 应用程序以在网络视图中显示我的自签名网站时,我遇到了相同的错误代码。
[ERROR:ssl_client_socket_impl.cc(935)] handshake failed; returned -1, SSL error code 1, net_error -202
这个链接解决了我的问题,也许它可以帮助你?
SLL错误修复
private X509Certificate[] mCertificates;
private PrivateKey mPrivateKey;
private void loadCertificateAndPrivateKey() {
try {
InputStream certificateFileStream = getClass().getResourceAsStream("/assets/cert.pfx");
KeyStore keyStore = KeyStore.getInstance("PKCS12");
String password = "password";
keyStore.load(certificateFileStream, password != null ? password.toCharArray() : null);
Enumeration<String> aliases = keyStore.aliases();
String alias = aliases.nextElement();
Key key = keyStore.getKey(alias, password.toCharArray());
if (key instanceof PrivateKey) {
mPrivateKey = (PrivateKey)key;
Certificate cert = keyStore.getCertificate(alias);
mCertificates = new X509Certificate[1];
mCertificates[0] = (X509Certificate)cert;
}
certificateFileStream.close();
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
private WebViewClient mWebViewClient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public void onReceivedClientCertRequest(WebView view, final ClientCertRequest request) {
if (mCertificates == null || mPrivateKey == null) {
loadCertificateAndPrivateKey();
}
request.proceed(mPrivateKey, mCertificates);
}
};