Installing Packages - PROXY Errors on Anaconda

Dear all,

I copied the notebook from Short Course 4 (AI Python for Beginners: Extending Python with Packages and APIs), lesson 5 (Installing Packages), but I am having problems.

I am unable to use the function requests.get.

I obtain the following error:
Request error: HTTPSConnectionPool(host=‘www.studiotecnicopagliai.it’, port=443): Max retries exceeded with url: /modifiche-interne-pregresse-ex-art-48-l-4785-carlo-pagliai/ (Caused by ProxyError(‘Cannot connect to proxy.’, OSError(‘Tunnel connection failed: 403 Forbidden’)))

Funny enough, the HTML extraction works well.
Code: HTML(f’')

I tried my best to solve this issue.
I also tried to make Anaconda exclude proxies, but I have no idea how to do…

Did anyone meet the same issue?

Thank you and best regards,

Alessio

PS: ChatGPT comments this:

Using requests.get() in Python:

  • When you use requests.get(), your Python script is making a direct HTTP request to the specified URL, and this request may be subject to proxy settings and network restrictions enforced by your system or network.
  • If your network enforces a proxy (or blocks direct requests), the request fails, which is why you get the ProxyError.

Here the starting code that is giving me problems:


#The url from one of the Batch’s newsletter
url = ‘https://www.studiotecnicopagliai.it/modifiche-interne-pregresse-ex-art-48-l-4785-carlo-pagliai/

#Unset proxy settings in the environment
import os
os.environ.pop(‘HTTP_PROXY’, None)
os.environ.pop(‘HTTPS_PROXY’, None)

try:
response = requests.get(url, timeout=10)
response.raise_for_status()
print(response.text)
except requests.exceptions.RequestException as e:
print(f"Request error: {e}")

Hi Alessio,

To bypass the proxy error, you can disable all proxy environment variables and explicitly instruct the requests library not to use any proxies. Use the proxies parameter in your requests.get() call to achieve this:

response = requests.get(url, timeout=10, proxies={'http': None, 'https': None})

Hope this helps!