-1

When I use requests.get on python3 on my personal wifi it works fine. However, the things I am trying to automate take place at work. This is my code

import requests

res = requests.get('https://automatetheboringstuff.com/files/rj.txt')

When at work, the below error occurs

Traceback (most recent call last):
  File "C:\Users\\[redacted]\AppData\Roaming\Python\Python37\site-packages\urllib3\connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "C:\Users\\[redacted]\AppData\Roaming\Python\Python37\site-packages\urllib3\util\connection.py", line 80, in create_connection
    raise err
  File "C:\Users\\[redacted]\AppData\Roaming\Python\Python37\site-packages\urllib3\util\connection.py", line 70, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

It looks like the firewall is keeping me from downloading any file at all. Is there any way around this?

Edit: I am able to download this file manually from the browser.

Matteo Zanoni
  • 1,901
  • 6
  • 19
  • 2
    Can you do this from a normal browser session? I mean using chrome directly and not through python. I understand that it would not be a definitive solution but it would help understanding the problem better (mainly seeing if it is just a proxy missing or a firewall blocking you) – Matteo Zanoni Jun 03 '21 at 12:59
  • Have you tried checking with your network administrator? You may just need [to set the proper proxies](https://stackoverflow.com/q/8287628/2745495) or tell your network admin to allow requests. – Gino Mempin Jun 03 '21 at 13:01
  • 3
    @MatteoZanoni I am able to download the file manually through chrome no problem. – Anthony Del Russo Jun 03 '21 at 13:25
  • Then it is probably not a firewall black but some other configuration and it is just a matter of configuring python correctly. Which OS are you on? can you share the internet configuration of your pc? I am mostly interested on proxy setup – Matteo Zanoni Jun 03 '21 at 13:27

1 Answers1

0

This is probably due to proxy. Check on your PC if you are using proxy and if you are note the ip and change your code like this:

import requests

proxies = {
    "http": "http://<proxy-ip>",
    "https": "https://<proxy-ip>",
}
res = requests.get('https://automatetheboringstuff.com/files/rj.txt', proxies=proxies)
Matteo Zanoni
  • 1,901
  • 6
  • 19