如何修复python中的“未能建立新连接:[Errno 10061]”错误?

2024-05-28 18:53:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我在执行python脚本时遇到问题。我总是犯同样的错误。错误是:

Failed to establish a new connection: [Errno 10061] No connection could be made because the target machine actively refused it. 

请注意,我的防火墙已禁用,而且我没有防病毒软件。同样,这个脚本在家里的另一台电脑上运行良好,但我需要它在这个系统上。你知道吗

我要做的是连接到一个API。我的代码是:

import requests
import time
import pycurl
import re
import certifi
import random
from pycurl import Curl
from io import BytesIO
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.chrome import options
from selenium.webdriver.common.action_chains import ActionChains
from random import randint
import os
import glob
import subprocess


aantalkeer = 1
max_aantalkeer = 2
while aantalkeer <= max_aantalkeer:
    print(str(aantalkeer) + "e keer")

    buffer = BytesIO()

    name = ["Lesli", "Prudence", "Paz", "Geraldo", "Regan", "Creola", "Adella", "Elsa", "Onie", "Abdoel", "Rochel",
            "Irwin", "Inocencia", "Linnea", "Ann", "Tomika", "Elvia", "Hosea", "Otha", "Bernardina"]
    browsertypes = ["mimic", "stealthfox", "mimic", "mimic", "mimic"]
    language = "nl-NL, nl;q=0.9,en-US;q=0.8,en;q=0.7"

    secure_random = random.SystemRandom()
    name = secure_random.choice(name)
    browsertype = secure_random.choice(browsertypes)
    token = "a01f2992e57c9b24f1ae5d085189a5ce8a888fd6"

    postfields = '{ "name": "' + str(name) + '", "browser": "' + str(browsertype) + '", "os": "win",' \
                                                                                    ' "navigator": { "language": "nl-NL,en-US;q=0.9,en;q=0.8" },' \
                                                                                    ' "timezone": { "mode": "FAKE", "fillBasedOnExternalIp": true },' \
                                                                                    ' "geolocation": { "mode": "PROMPT", "fillBasedOnExternalIp": true },' \
                                                                                    ' "webRTC": { "mode": "FAKE", "fillBasedOnExternalIp": true },' \
                                                                                    ' "audioContext": { "mode": "NOISE" }, "canvas": { "mode": "NOISE" } }'

    headers = ['Content-type: application/json', 'Authorization: BasicBase64EncodedApiKeyAndPassword']
    c = Curl = pycurl.Curl()
    c.setopt(pycurl.CAINFO, certifi.where())
    c.setopt(c.URL, 'https://api.multiloginapp.com/v2/profile?token='+token+'&defaultMode=REAL')
    c.setopt(c.HTTPHEADER, headers)
    c.setopt(c.POST, 1)
    c.setopt(c.POSTFIELDS, postfields)
    c.setopt(c.WRITEDATA, buffer)
    c.perform()
    c.close()

    body= bytes = buffer.getvalue()

    body= stri = body.decode('utf-8')
    body= stri = re.sub('[^A-Za-z0-9-]+', ' ', body)
    body= stri = body.replace('uuid ', '')
    body= stri = body.replace('/s', '')
    profileid = re.sub('^(\s+)', "", body)
    profileid = re.sub(r'\s+$', "", profileid)

    print(profileid)

    mla_port = "35000"
    mla_url = 'https://localhost:'+ mla_port +'/api/v1/profile/start?automation=true&profileId=' + profileid
    resp = requests.get(mla_url)
    json = resp.json()
    opts = options.DesiredCapabilities()

    googlelinks = ["https://www.google.com", "https://www.google.nl"]
    secure_random = random.SystemRandom()
    googlelink = secure_random.choice(googlelinks)

请帮帮我:)


Tags: namefromimportremodeseleniumbodyrandom
1条回答
网友
1楼 · 发布于 2024-05-28 18:53:11

基本上,这意味着在您试图通过IP地址连接到的端口上没有任何侦听内容。您可能需要检查防火墙,因为它可能会阻止某个端口。这可能发生,因为您的防火墙可能会保护您免受黑客攻击,因为您的信息可能会从此处泄漏。你知道吗

相关问题 更多 >

    热门问题