Trouble renewing Tor IP address on Windows 11 using stem library

I’m trying to automate the renewal of Tor IP addresses using Python on Windows 11 with the stem library. However, I keep encountering the following error:

Error renewing Tor IP: [WinError 10061] No connection could be made because the target computer actively refused it

My Code:

import subprocess  # Import subprocess module for starting Tor
from stem import Signal
from stem.control import Controller
import requests
import shutil
import os
import time
import sys


def start_tor():
    try:
        tor_path = r"C:UsersanjoyerDesktopTor BrowserBrowserTorBrowserTortor.exe"
        subprocess.Popen([tor_path])
        print("Tor started successfully.")
        time.sleep(5)  # Give Tor some time to start up (adjust as needed)
    except Exception as e:
        print(f"Error starting Tor: {e}")


def renew_tor_ip():
    try:
        with Controller.from_port(port=9051) as controller:
            controller.authenticate(password='HashedControlPassword')
            controller.signal(Signal.NEWNYM)
            print("Tor IP renewed successfully.")
    except Exception as e:
        print(f"Error renewing Tor IP: {e}")

proxies = {
    'http': 'socks5h://127.0.0.1:9050',
    'https': 'socks5h://127.0.0.1:9050'
}


def get_new_ip():
    renew_tor_ip()
    response = requests.get('http://httpbin.org/ip', proxies=proxies)
    return response.json()


if __name__ == "__main__":
    start_tor()  # Start Tor
    renew_tor_ip()

    while True:
        time.sleep(300) 
        renew_tor_ip()  

torrc:

ControlPort 9051
HashedControlPassword HashedControlPassword

Tor starts successfully when I execute my script, and the console outputs the following information:

Tor started successfully.
Jun 23 19:25:59.793 [notice] Tor 0.4.8.12 (git-2beaa7557c3c93ec) running on Windows 8 [or later] with Libevent 2.1.12-stable, OpenSSL 3.0.14, Zlib 1.3.1, Liblzma N/A, Libzstd N/A and Unknown N/A as libc.
Jun 23 19:25:59.793 [notice] Tor can't help you if you use it wrong! Learn how to be safe at https://support.torproject.org/faq/staying-anonymous/
Jun 23 19:25:59.801 [notice] Configuration file "C:UsersanjoyerAppDataRoamingtortorrc" not present, using reasonable defaults.
Jun 23 19:25:59.801 [warn] Path for GeoIPFile (<default>) is relative and will resolve to C:Usersanjoyerdesktop<default>. Is this what you wanted?
Jun 23 19:25:59.801 [warn] Path for GeoIPv6File (<default>) is relative and will resolve to C:Usersanjoyerdesktop<default>. Is this what you wanted?
Jun 23 19:25:59.803 [notice] Opening Socks listener on 127.0.0.1:9050
Jun 23 19:25:59.803 [notice] Opened Socks listener connection (ready) on 127.0.0.1:9050
Jun 23 19:25:59.000 [notice] Bootstrapped 0% (starting): Starting
Jun 23 19:26:00.000 [notice] Starting with guard context "default"
Jun 23 19:26:01.000 [notice] Bootstrapped 5% (conn): Connecting to a relay
Jun 23 19:26:01.000 [notice] Bootstrapped 10% (conn_done): Connected to a relay
Jun 23 19:26:01.000 [notice] Bootstrapped 14% (handshake): Handshaking with a relay
Jun 23 19:26:02.000 [notice] Bootstrapped 15% (handshake_done): Handshake with a relay done
Jun 23 19:26:02.000 [notice] Bootstrapped 75% (enough_dirinfo): Loaded enough directory info to build circuits
Jun 23 19:26:02.000 [notice] Bootstrapped 90% (ap_handshake_done): Handshake finished with a relay to build circuits
Jun 23 19:26:02.000 [notice] Bootstrapped 95% (circuit_create): Establishing a Tor circuit
Jun 23 19:26:03.000 [notice] Bootstrapped 100% (done): Done
Error renewing Tor IP: [WinError 10061] No connection could be made because the target computer actively refused it

I’ve configured the torrc file with ControlPort 9051 and HashedControlPassword.
I’ve started Tor manually and verified it’s running.
I’ve checked my firewall settings to ensure Tor has permissions on port 9051 and tor.exe.

New contributor

Castle Thief thief cake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật