juancarlospaco / faster-than-requests

Faster requests on Python 3
https://gist.github.com/juancarlospaco/37da34ed13a609663f55f4466c4dbc3e
MIT License
1.09k stars 91 forks source link

Script breaking after exact 396 requests #181

Closed caioluccas closed 2 years ago

caioluccas commented 2 years ago

for some reason when I use faster than requests to send many requests to a url in the 396 request the script closes and no error is showing, when i use the request lib it works normally. is there any reason?

juancarlospaco commented 2 years ago

Again we need the full repro code to understand.

Are you calling close() after the request is done?, theres a refactor pending to not need the call to close() anymore, but is still to be done.

caioluccas commented 2 years ago

No im not calling close(), its just crashing in 396 request for no reason and its not returning a error

this is the code:

while task_ended == False:
    for token in alt_tokens:
      headers = {"Authorization": "Bearer " + token}
      check_availability = requests.get(endpoint, http_headers=headers)

      if check_availability.status_code == 200:
        count = count + 1
        print(f'[League Sniper] Target Nick: {target_nick} | Requests: {count} | Response: {check_availability.text} | Currency: {currency.upper()}')
        if check_availability.text == "true":
          buy = req.post(change_nick_url, json=payload, headers=main_headers)
          if buy.status_code == 200:
            os.system('cls')
            print(ascii.league_sniper_ascii + "\n")
            print(f'[League Sniper] You have been sniped {target_nick} in 0 requests. ({username}:{passw})')
            os.system('pause')
            task_ended = True
            break
     else:
          print(check_availability.status_code)
juancarlospaco commented 2 years ago

You have to call close_client() after the request, it is failing because you are opening too much sockets too fast, the OS is the one killing it.

This is not ideal, in the future it will not be needed, but until then you have to call faster_than_requests.close_client().

caioluccas commented 2 years ago

ok, i will try, thanks man

caioluccas commented 2 years ago

i tried using it in two different ways and now it's just closing after the first request

first way:

  while task_ended == False:
    for token in alt_tokens:
      headers = [("Authorization", "Bearer " + token)]
      check_availability = requests.get(endpoint, http_headers=headers)
      if check_availability[2] == "200 OK":
        count = count + 1
        print(f'[League Sniper] Target Nick: {target_nick} | Requests: {count} | Response: {check_availability[0]} | Currency: {currency.upper()}')
        requests.close_client()
        if check_availability[0] == "true":
          buy = requests.post(change_nick_url, body=payload, http_headers=main_headers)
          if buy[2] == "200 OK":
            os.system('cls')
            print(ascii.league_sniper_ascii + "\n")
            print(f'[League Sniper] You have been sniped {target_nick} in {count} requests. ({username}:{passw})')
            os.system('pause')
            task_ended = True
            break
     else:
          print(check_availability[2])

second way:

  while task_ended == False:
    for token in alt_tokens:
      headers = [("Authorization", "Bearer " + token)]
      check_availability = requests.get(endpoint, http_headers=headers)
      requests.close_client()
      if check_availability[2] == "200 OK":
        count = count + 1
        print(f'[League Sniper] Target Nick: {target_nick} | Requests: {count} | Response: {check_availability[0]} | Currency: {currency.upper()}')
        if check_availability[0] == "true":
          buy = requests.post(change_nick_url, body=payload, http_headers=main_headers)
          if buy[2] == "200 OK":
            os.system('cls')
            print(ascii.league_sniper_ascii + "\n")
            print(f'[League Sniper] You have been sniped {target_nick} in {count} requests. ({username}:{passw})')
            os.system('pause')
            task_ended = True
            break
     else:
          print(check_availability[2])
juancarlospaco commented 2 years ago

The second way looks okey, but you have to call it for the post() too.

caioluccas commented 2 years ago

the script crashes before the post request

caioluccas commented 2 years ago

after the get request in 4 line the script closes