Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python – Connection Reset

I am currently working on a project to download .mp4 files from links from a text document, and it works with this code

import urllib.request
import random
import threading

def request(line):
    urllib.request.urlretrieve(line, 'D:\\example_directory\\' +
                               str(random.randint(1000000, 9999999)) + "-69" +
                               str(random.randint(100, 999)) + "-" +
                               str(random.randint(1000000, 9999999)) + ".mp4")

with open('D:\\example_directory\\links.txt') as f:
    for line in f:
        print(line)
        threading.Thread(target=request, args=(line,)).start()

I want to use this code to download videos from a website which is built for streaming, and therefore caps the download speed after around 5 seconds to 120kb/s. I found a bypass for this limitation: resetting your connection. Resetting your connection can be manually achieved by plugging the ethernetcable in and out or turning WiFi on and off again.

I want to know if there is any way to reset the connection, without having to plugin and out the cable / turn on and off the WiFi. Like a package or function that can be imported, but also a glitch would help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can reset your connection, like you said, by reconnecting to the network.
There is, as of my knowlegde, no module to intentionally reset a connection, but you can achieve a simular result using this method:

  • first, connect via Ethernet (cable)
  • then use the "winwifi" module, to reset your connection
    example:
import winwifi
def reset():
  winwifi.disconnect()

because you are connected to ethernet, the connection is restored within a fraction of a second, and therefore, resets.
I hope this helped you and have a great journey on your coding adventures 😉

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading