如何解决python中的“无法建立新连接:[Errno 10061]”错误?

时间:2019-05-07 13:58:12

标签: python python-3.x selenium python-requests failed-to-connect

我在执行python脚本时遇到问题。我不断收到相同的错误。错误是:

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

请注意,我的防火墙已禁用,而且我没有防病毒软件。同样,这个脚本在家里的另一台PC上也可以正常工作,但在此系统上我需要它。

我想做的是连接到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)

请帮助我:)

1 个答案:

答案 0 :(得分:0)

基本上,这意味着您尝试通过IP地址连接到的端口上没有任何监听。您可能需要检查防火墙,因为它可能会阻止某个端口。这可能是因为您的防火墙可能正在保护您免受黑客攻击,因为您的信息可能因此而被泄漏。