Skip to content

Commit 775cc60

Browse files
authored
add timeout to get_psm3 (#741)
* add timeout * update whatsnew
1 parent 879cb46 commit 775cc60

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

docs/sphinx/source/whatsnew/v0.7.0.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ Removal of prior version deprecations
132132
* Removed `ModelChain.prepare_inputs` clearsky assumption when no irradiance
133133
data was provided.
134134

135+
Enhancements
136+
~~~~~~~~~~~~
137+
* Add `timeout` to :py:func:`pvlib.iotools.get_psm3`.
138+
139+
135140
Contributors
136141
~~~~~~~~~~~~
137142
* Mark Campanellli (:ghuser:`markcampanelli`)

pvlib/iotools/psm3.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
22-
full_name=PVLIB_PYTHON, affiliation=PVLIB_PYTHON):
22+
full_name=PVLIB_PYTHON, affiliation=PVLIB_PYTHON, timeout=30):
2323
"""
2424
Get PSM3 data
2525
@@ -43,6 +43,8 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
4343
optional
4444
affiliation : str, default 'pvlib python'
4545
optional
46+
timeout : int, default 30
47+
time in seconds to wait for server response before timeout
4648
4749
Returns
4850
-------
@@ -140,7 +142,7 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
140142
'interval': interval
141143
}
142144
# request CSV download from NREL PSM3
143-
response = requests.get(URL, params=params)
145+
response = requests.get(URL, params=params, timeout=timeout)
144146
if not response.ok:
145147
# if the API key is rejected, then the response status will be 403
146148
# Forbidden, and then the error is in the content and there is no JSON

0 commit comments

Comments
 (0)