Skip to content
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

Added proxy settings #65

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion fredapi/fred.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
quote_plus = url_parse.quote_plus
urlencode = url_parse.urlencode
HTTPError = url_error.HTTPError
proxy_handler = url_request.ProxyHandler
build_opener = url_request.build_opener
install_opener = url_request.install_opener


class Fred:
Expand All @@ -28,7 +31,8 @@ class Fred:

def __init__(self,
api_key=None,
api_key_file=None):
api_key_file=None,
proxies=None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add an explanation in the docstring below about how proxies can be used?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take care, sure. I will also add a parameter to specify ssl verification. I'll send a PR in the next couple days.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here: #71

"""
Initialize the Fred class that provides useful functions to query the Fred dataset. You need to specify a valid
API key in one of 3 ways: pass the string via api_key, or set api_key_file to a file with the api key in the
Expand All @@ -55,6 +59,11 @@ def __init__(self,
api key. You can sign up for a free api key on the Fred
website at http://research.stlouisfed.org/fred2/"""))

self.proxies = proxies
if self.proxies is not None:
opener = build_opener(proxy_handler(self.proxies))
install_opener(opener)

def __fetch_data(self, url):
"""
helper function for fetching data given a request URL
Expand Down