Skip to content

add timeout to get_psm3 #741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/sphinx/source/whatsnew/v0.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ Testing
* Added 30 minutes to timestamps in `test_psm3.csv` to match change in NSRDB (:issue:`733`)


Enhancements
~~~~~~~~~~~~
* Add `timeout` to :py:func:`pvlib.iotools.get_psm3`.


Contributors
~~~~~~~~~~~~
* Mark Campanellli (:ghuser:`markcampanelli`)
* Will Holmgren (:ghuser:`wholmgren`)
* Cliff Hansen (:ghuser:`cwhanse`)
* Oscar Dowson (:ghuser:`odow`)
6 changes: 4 additions & 2 deletions pvlib/iotools/psm3.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
full_name=PVLIB_PYTHON, affiliation=PVLIB_PYTHON):
full_name=PVLIB_PYTHON, affiliation=PVLIB_PYTHON, timeout=30):
"""
Get PSM3 data

Expand All @@ -47,6 +47,8 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
optional
affiliation : str, default 'pvlib python'
optional
timeout : int, default 30
time in seconds to wait for server response before timeout

Returns
-------
Expand Down Expand Up @@ -144,7 +146,7 @@ def get_psm3(latitude, longitude, api_key, email, names='tmy', interval=60,
'interval': interval
}
# request CSV download from NREL PSM3
response = requests.get(URL, params=params)
response = requests.get(URL, params=params, timeout=timeout)
if not response.ok:
# if the API key is rejected, then the response status will be 403
# Forbidden, and then the error is in the content and there is no JSON
Expand Down