Force a python package that uses requests to go through a proxy

116 Views Asked by At

I am currently using the python package meteostat. It makes use of the requests package to download data off the meteostat servers. I am running this package through work a machine that needs to use an http proxy.

When running their example code:

from datetime import datetime
import matplotlib.pyplot as plt
from meteostat import Stations, Monthly

# Set time period
start = datetime(2000, 1, 1)
end = datetime(2018, 12, 31)

# Get Monthly data
data = Monthly('10637', start, end)
data = data.fetch()

# Plot line chart including average, minimum and maximum temperature
data.plot(y=['tavg', 'tmin', 'tmax'])
plt.show()

I get the following error at data.fetch():

URLError: <urlopen error [Errno 2] No such file or directory>

I believe this is due to the fact that I am not going through my work's proxy, like I have to when I install packages via pip.

I have tried adding the following to my code, but it did not resolve the issue:

import requests

proxies = {
   'http': 'WORK PROXY',
   'https': 'WORK PROXY',
}
0

There are 0 best solutions below