Python Forum
Proxy Checking Software Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Proxy Checking Software Error
#1
Hey guys i have this code that i have been working on and all it does is checks if a proxy is valid or not. Though it produces no error, it dosent seem to be working because when i add bad proxies on purpose it still prints out as if it is working. im not sure why this is the case and would appreciate some help.

def check_proxies():
    print('[#] Checking proxies now ')
    def check_proxies(proxy):
        try:
            r = requests.get('https://www.test.com/', proxies={'http':proxy}, timeout=3)
            if r.status_code == 200:
                fproxy.append(proxy)
                print(Fore.GREEN + 'Working proxy --> ', proxy)
            else:
                print(Fore.RED + 'Not working proxy --> ', proxy)
                pass
        except TimeoutError:
            pass
        except ConnectionError:
            pass
    def proxies(proxy):
        with concurrent.futures.ThreadPoolExecutor(max_workers=30) as executor:
            executor.map(check_proxies, proxy)
    proxies(proxy)
buran write Jan-19-2021, 08:54 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
for start, I would not use check_proxies as name for both outer and nested function and also would not nest function like this - it just complicates the code (flat is better than nested remember?)
also, unless proxy you pass on line 19 is some sort of collection (in which case plural name is more appropriate) I don't see the point of using ThreadPoolExecuter and passing str will probably cause an error.

I think the problem is that you requests https while proxy is defined only for http schema and thus for https it is overridden by system defaults.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Jan-19-2021, 09:06 AM)buran Wrote: for start, I would not use check_proxies as name for both outer and nested function and also would not nest function like this - it just complicates the code (flat is better than nested remember?)
also, unless proxy you pass on line 19 is some sort of collection (in which case plural name is more appropriate) I don't see the point of using ThreadPoolExecuter and passing str will probably cause an error.

I think the problem is that you requests https while proxy is defined only for http schema and thus for https it is overridden by system defaults.

proxy is a list. and i have changed the function name. the point of a threadpoolexecutor is to check faster using threads. and how do i use both, HTTP and HTTPs proxies? cause its a mix of them
Reply
#4
(Jan-19-2021, 09:16 AM)rizzla Wrote: and how do i use both, HTTP and HTTPs proxies? cause its a mix of them
define both http and https schema in proxies dict. As I said, I think because your url is https and you provide only proxy for http schema it uses system defaults
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
(Jan-19-2021, 09:32 AM)buran Wrote:
(Jan-19-2021, 09:16 AM)rizzla Wrote: and how do i use both, HTTP and HTTPs proxies? cause its a mix of them
define both http and https schema in proxies dict. As I said, I think because your url is https and you provide only proxy for http schema it uses system defaults

so whats happening is that i have another piece of code at the bottom which is scrapping proxies from another site. and then appending to a list object called proxy. now these proxies are a mix of http and https.

i tried changing that part to this:
but now since i changed the method to `https` it dosent print anything. im not sure why this problem arised tho. 
import requests
from bs4 import BeautifulSoup as bs
import concurrent.futures
from colorama import Fore
proxy = []
fproxy = []
def check_proxies_def():
    print('[#] Checking proxies now ')
    def check_proxies(proxy):
        try:
            r = requests.get('https://www.epicgames.com/id/api/account/name/state/test', proxies={'https':proxy}, timeout=3)
            if r.status_code == 200:
                fproxy.append(proxy)
                print(Fore.GREEN + 'Working proxy --> ', proxy)
            else:
                print(Fore.RED + 'Not working proxy --> ', proxy)
                pass
        except TimeoutError:
            pass
        except ConnectionError:
            pass
    def proxies(proxy):
        with concurrent.futures.ThreadPoolExecutor(max_workers=30) as executor:
            executor.map(check_proxies, proxy)
    proxies(proxy)  
Reply
#6
(Jan-19-2021, 09:32 AM)buran Wrote:
(Jan-19-2021, 09:16 AM)rizzla Wrote: and how do i use both, HTTP and HTTPs proxies? cause its a mix of them
define both http and https schema in proxies dict. As I said, I think because your url is https and you provide only proxy for http schema it uses system defaults
now in the above code u may ntoice that i changed the proxy to https
the error that now arises is that nothing prints out. it dosent check anything
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error while checking for key in Dictionary onenessboy 5 2,595 Aug-14-2020, 01:06 PM
Last Post: onenessboy

Forum Jump:

User Panel Messages

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