Python Forum
Unable to use random.choice(list) in async method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to use random.choice(list) in async method
#1
I need to pull a random proxy from a list in an async method but the code exits the method as soon as it hits the line of code:
proxy = random.choice(proxy_list)
Here's the full method and the next line (the "print" line) never executes.
async def download_site(session, url):
    proxy_list = [
    (754, '38.39.205.220:80'),
    (681, '38.39.204.100:80'),
    (682, '38.39.204.101:80'),
    (678, '38.39.204.94:80')
    ]
    proxy = random.choice(proxy_list)
    print(proxy[1])
    async with session.get(url, proxy="http://" + proxy[1]) as response:
        print("Read {0} from {1}".format(response.content_length, url))
Can someone please share a work-around or a fix for this?
Thanks.
Reply


Messages In This Thread
Unable to use random.choice(list) in async method - by spacedog - Apr-29-2021, 06:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  unable to remove all elements from list based on a condition sg_python 3 451 Jan-27-2024, 04:03 PM
Last Post: deanhystad
  Sample random, unique string pairs from a list without repetitions walterwhite 1 461 Nov-19-2023, 10:07 PM
Last Post: deanhystad
Question mypy unable to analyse types of tuple elements in a list comprehension tomciodev 1 484 Oct-17-2023, 09:46 AM
Last Post: tomciodev
  combobox_callback(choice choice part of openfile name (kind of dependency) janeik 9 1,453 Sep-10-2023, 10:27 PM
Last Post: janeik
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,249 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  List of random numbers astral_travel 17 2,723 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,527 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  Question about List.reverse() method tomliuwhite 1 1,359 Dec-07-2021, 08:20 AM
Last Post: ndc85430
  get data from 2 async functions korenron 0 1,227 Sep-22-2021, 08:39 AM
Last Post: korenron
  random.choice HELP samuelbachorik 4 2,279 Aug-18-2021, 03:24 PM
Last Post: naughtyCat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020