Python Forum
Prevent urllib.request from using my local proxy
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prevent urllib.request from using my local proxy
#1
Using the code below I can still pull a page from the web. Where you see:
'xxxx'

Should be a valid proxy.
proxy_handler = urllib.request.ProxyHandler({'http': 'xxxx'}) 
opener = urllib.request.build_opener(proxy_handler)
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)  
urllib.request.urlopen(url) 
and using 'xxxx' I should get an exception on the last line, but it continues to execute and pull the page. The reason for this is found here: https://www.decalage.info/en/python/urllib2noproxy

"If no proxy is explicitly specified, urllib2 will use Internet Explorer proxy settings by default."

BUT... even though I "do" explicitly specify a proxy (a known bad proxy) it will still revert to using my proxy and continue executing.

I need to prevent it from using any local proxy and "Only" the proxy I pass in. If it fails I need to know, log it and try another proxy.

Can someone please tell me how to block it from using my local proxy?

Thank you.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using SQLAlchemy, prevent SQLite3 table update by multiple program instances Calab 3 755 Aug-09-2023, 05:51 PM
Last Post: Calab
  urllib can't find "parse" rjdegraff42 6 2,188 Jul-24-2023, 05:28 PM
Last Post: deanhystad
Smile How we can prevent screen recording murad_ali 3 1,838 Jul-29-2022, 10:29 AM
Last Post: DeaD_EyE
  How to prevent python from going to new line in for loop? idknuttin 3 4,944 Feb-11-2022, 05:40 AM
Last Post: deanhystad
  how can I correct the Bad Request error on my curl request tomtom 8 5,083 Oct-03-2021, 06:32 AM
Last Post: tomtom
  urllib.request.ProxyHandler works with bad proxy spacedog 0 5,934 Apr-24-2021, 08:02 AM
Last Post: spacedog
  Need help with XPath using requests,time,urllib.request and BeautifulSoup spacedog 3 2,860 Apr-24-2021, 02:48 AM
Last Post: bowlofred
  Help with urllib.request Brian177 2 2,879 Apr-21-2021, 01:58 PM
Last Post: Brian177
  urllib.request ericmt123 2 2,449 Dec-21-2020, 06:53 PM
Last Post: Larz60+
  Cannot open url link using urllib.request Askic 5 6,684 Oct-25-2020, 04:56 PM
Last Post: Askic

Forum Jump:

User Panel Messages

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