Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 176305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:51:10+00:00 2026-05-11T13:51:10+00:00

I have written a script in python that uses cookies and POST/GET. I also

  • 0

I have written a script in python that uses cookies and POST/GET. I also included proxy support in my script. However, when one enters a dead proxy, the script crashes. Is there any way to check if a proxy is dead/alive before running the rest of my script?

Furthermore, I noticed that some proxies don’t handle cookies/POST headers properly. Is there any way to fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:51:10+00:00Added an answer on May 11, 2026 at 1:51 pm

    The simplest was is to simply catch the IOError exception from urllib:

    try:     urllib.urlopen(         'http://example.com',         proxies={'http':'http://example.com:8080'}     ) except IOError:     print 'Connection error! (Check proxy)' else:     print 'All was fine' 

    Also, from this blog post – ‘check status proxy address’ (with some slight improvements):

    for python 2

    import urllib2 import socket  def is_bad_proxy(pip):         try:         proxy_handler = urllib2.ProxyHandler({'http': pip})         opener = urllib2.build_opener(proxy_handler)         opener.addheaders = [('User-agent', 'Mozilla/5.0')]         urllib2.install_opener(opener)         req=urllib2.Request('http://www.example.com')  # change the URL to test here         sock=urllib2.urlopen(req)     except urllib2.HTTPError, e:         print 'Error code: ', e.code         return e.code     except Exception, detail:         print 'ERROR:', detail         return True     return False  def main():     socket.setdefaulttimeout(120)      # two sample proxy IPs     proxyList = ['125.76.226.9:80', '213.55.87.162:6588']      for currentProxy in proxyList:         if is_bad_proxy(currentProxy):             print 'Bad Proxy %s' % (currentProxy)         else:             print '%s is working' % (currentProxy)  if __name__ == '__main__':     main() 

    for python 3

    import urllib.request import socket import urllib.error  def is_bad_proxy(pip):         try:         proxy_handler = urllib.request.ProxyHandler({'http': pip})         opener = urllib.request.build_opener(proxy_handler)         opener.addheaders = [('User-agent', 'Mozilla/5.0')]         urllib.request.install_opener(opener)         req=urllib.request.Request('http://www.example.com')  # change the URL to test here         sock=urllib.request.urlopen(req)     except urllib.error.HTTPError as e:         print('Error code: ', e.code)         return e.code     except Exception as detail:         print('ERROR:', detail)         return True     return False  def main():     socket.setdefaulttimeout(120)      # two sample proxy IPs     proxyList = ['125.76.226.9:80', '25.176.126.9:80']      for currentProxy in proxyList:         if is_bad_proxy(currentProxy):             print('Bad Proxy %s' % (currentProxy))         else:             print('%s is working' % (currentProxy))  if __name__ == '__main__':     main()  

    Remember this could double the time the script takes, if the proxy is down (as you will have to wait for two connection-timeouts).. Unless you specifically have to know the proxy is at fault, handling the IOError is far cleaner, simpler and quicker..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 207k
  • Answers 207k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It seems as if I have found a solution: In… May 12, 2026 at 9:18 pm
  • Editorial Team
    Editorial Team added an answer Every variable in the d-t language is represented as a… May 12, 2026 at 9:18 pm
  • Editorial Team
    Editorial Team added an answer Something like this perhaps? $string = preg_replace('#\[youtube\].*?name="movie" value="(.*?)".*?\[/youtube\]#i', "[URL=$1]$1[/URL]", $string);… May 12, 2026 at 9:18 pm

Related Questions

I have a Python 2.6 script that is gagging on special characters, encoded in
I'm currently in the middle of porting a fairly large Perl The problem is
Is there a simple way to run a Python script on Windows/Linux/OS X? On
I've written a setup.py script for py2exe, generated an executable for my python GUI

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.