Skip to content

Commit 1c28894

Browse files
authored
Merge pull request #1 from pajot/dev
Use python requests library instead of urllib5
2 parents 8b8bb2a + 7e63296 commit 1c28894

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

example/basic_example.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pandas as pd
55
import logging
66
import os
7-
from urllib.request import urlretrieve
7+
import requests
88

99
try:
1010
from matplotlib import pyplot as plt
@@ -44,8 +44,9 @@ def download_file(filename, url):
4444
if not os.path.isfile(filename):
4545
logging.info('Copying weather data from {0} to {1}'.format(
4646
url, filename))
47-
urlretrieve(url, filename)
48-
47+
req = requests.get(url)
48+
with open(filename, 'wb') as fout:
49+
fout.write(req.content)
4950

5051
def fetch_example_files():
5152
basic_path = os.path.join(os.path.expanduser("~"), '.oemof')

windpowerlib/basicmodel.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import numpy as np
55
import pandas as pd
6-
from urllib.request import urlretrieve
6+
import requests
77

88

99
class SimpleWindTurbine:
@@ -326,7 +326,9 @@ def read_wpp_data(**kwargs):
326326
if not os.path.exists(cp_path):
327327
os.makedirs(cp_path)
328328
if not os.path.isfile(filepath + suffix):
329-
urlretrieve(url + suffix, filepath + suffix)
329+
req = requests.get(url + suffix)
330+
with open(filepath + suffix, 'wb') as fout:
331+
fout.write(req.content)
330332
logging.info('Copying cp_values from {0} to {1}'.format(
331333
url, filepath + suffix))
332334
logging.debug('Retrieving cp values from {0}'.format(
@@ -339,7 +341,9 @@ def read_wpp_data(**kwargs):
339341
logging.debug('Retrieving cp values from {0}'.format(
340342
filename + suffix))
341343
if not os.path.isfile(filename + suffix):
342-
urlretrieve(url + suffix, filename + suffix)
344+
req = requests.get(url + suffix)
345+
with open(filename + suffix, 'wb') as fout:
346+
fout.write(req.content)
343347
logging.info('Copying cp_values from {0} to {1}'.format(
344348
url, filename + suffix))
345349
df = pd.read_csv(filename + suffix, index_col=0)

0 commit comments

Comments
 (0)